0
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_)

Currently the way its set up it can generate a linear model but for my data I need an exponential one, the problem is I dont fully understand the linear = linear_model.LinearRegression() part of the code. Its using sklearn which ive looked into but cannot find an exponential equivalent. If someone can replace that line with an exponential equivalent that would be amazing.

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

0

You can use Support Vector Regression with RBF kernel.

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)
igrinis
  • 12,398
  • 20
  • 45
  • SO ive tried every kernal and they all give me very low accuracy scores, the linear model gives me a 99% score but it only works after my x is around 100 so im not sure why it has such a high rate. the graph is definitally not linear though. – Andrew Kaplan Jun 13 '20 at 20:29
  • You may need to preprocess your data. SVM works better when data is in range ~[-1:1]. See updated code. – igrinis Jun 14 '20 at 11:54
  • It occurred to me that I may understand you question wrong. May be [this](https://stackoverflow.com/questions/3433486/how-to-do-exponential-and-logarithmic-curve-fitting-in-python-i-found-only-poly) is what you seek for? – igrinis Jun 14 '20 at 11:58