【问题标题】:I need an Exponential/non-linear model in python我需要python中的指数/非线性模型
【发布时间】:2020-10-02 23:04:40
【问题描述】:
import numpy as np
import sklearn
from sklearn import linear_model
from sklearn.utils import shuffle

data = pd.read_csv('student-mat.csv', sep=';')

predict = 'Markup'

x = np.array(data.drop([predict], 1))
y = np.array(data[predict])

x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.1)

linear = linear_model.LinearRegression()

linear.fit(x_train, y_train)
acc = linear.score(x_test, y_test)
print(acc)

print(linear.coef_)
print(linear.intercept_)

目前它的设置方式可以生成线性模型,但对于我的数据我需要一个指数模型,问题是我不完全理解代码的linear = linear_model.LinearRegression() 部分。它使用我调查过但找不到指数等价物的sklearn。如果有人可以用指数等价物替换那条线,那将是惊人的。

【问题讨论】:

标签: python machine-learning scikit-learn regression non-linear-regression


【解决方案1】:

您可以将Support Vector Regression 与 RBF 内核一起使用。

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

nonlin_rg = sklearn.SVR(kernel='rbf', C=0.5, epsilon=0.2)

model = make_pipeline(StandardScaler(), nonlin_rg)
model.fit(x_train, y_train)

acc = model.score(x_test, y_test)

【讨论】:

  • 所以我尝试了每一个内核,它们都给了我非常低的准确度分数,线性模型给了我 99% 的分数,但它只在我的 x 大约为 100 后才有效,所以我不确定它为什么会有这样的分数高比率。该图绝对不是线性的。
  • 您可能需要对数据进行预处理。当数据在 ~[-1:1] 范围内时,SVM 工作得更好。查看更新的代码。
  • 突然想到我可能理解你的问题是错误的。可能是this 是你要找的吗?
猜你喜欢
  • 2020-06-03
  • 2019-06-09
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
  • 2019-08-19
  • 2013-05-15
  • 2019-09-22
  • 2015-05-26
相关资源
最近更新 更多