Логарифмическая линейная регрессия с нормальным масштабом - PullRequest
0 голосов
/ 18 июня 2020
• 1000 slope (b1) со следующими данными: Затем для вычисления значения y при следующих значениях x; при x = 50 и x = 84,1.

Ось x должна быть в вероятностном масштабе, а ось y - в логарифмическом нормальном масштабе. Я не уверен, что метод, который я написал, верен для реализации линейной регрессии в логарифмической шкале нормальных вероятностей и расчета коэффициентов.

Я использую следующий код:

from matplotlib import pyplot as plt
import seaborn
import probscale
from pylab import *
import numpy as np

# Permeability values (mD)
y = [283, 650, 565, 407, 714, 500, 730, 900, 420, 591, 381, 430, 324, 440, 1212, 315, 450]

# Permeability values in descending order (y, mD)
y.sort(reverse = True)
print('Permeability values in Descending Order :', y)

# Percentage of samples with larger permeability (x, %)
x = tuple([round(n/len(y)*100, 1) for n in range(len(y))])
print('Percentage of samples with larger permeability :', x)

# Plot
fig, ax = plt.subplots(figsize=(10, 8))
ax.set_xlim(0.01, 99)
ax.set_xscale('prob')
ax.set_ylim(1e0, 1e4)
ax.set_yscale('log')
seaborn.despine(fig=fig)
plt.plot(x, y, 'go')
plt.title('Permeability Variation')
plt.ylabel('Permebility, md')
plt.xlabel('Percent of Samples with Larger Permeability, %')
plt.grid(True)
plt.show()

# Mean for x and y
mean_x = np.mean(x)
mean_y = np.mean(y)

# Total number of values
m = len(x)

# Calculate b1 and b0
numer = 0
denom = 0
for i in range(m):
    numer += (x[i] - mean_x) * (y[i] - mean_y)
    denom += (x[i] - mean_x) ** 2
b1 = numer / denom
b0 = mean_y - (b1 * mean_x)

# Print coefficients
print('b1 = ', b1, 'b0 = ', b0)

# Calculate permeability at 84.1% and 50% probability (Percentiles)
# Calculate variance for permeability distribution (VDP)
k1 = b0 + b1 * 50
k2 = b0 + b1 * 84.1

# Dykstra Parsons Formula 'VDP' (k1=@50% Percentile and k2=@84.1% Percentile)
vdp = (k1 - k2) / k1
print('vdp = ', vdp)

# Calculate r^2 score (Coefficient of Correlation)
sumofsquares = 0
sumofresiduals = 0
for i in range(m):
    y_pred = b0 + b1 * x[i]
    sumofsquares += (y[i] - mean_y) ** 2
    sumofresiduals += (y[i] - y_pred) ** 2
score = 1 - (sumofresiduals / sumofsquares)
print('R^2 score = ', score)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...