Issue
I am trying to learn how to use sklearn, TF, pandas within pycharm. I was able to successfully import the above mentioned libraries and test the code to make sure they are functioning by printing the accuracy after train and test. All of the other capabilities inside of sklearn work without issue including linear_model and LinearRegression(); however when I attempt to use linear.coef_ or linear.predict() I receive an error for unresolved reference 'linear'. The documentation I found online shows all the above functions are part of the same library. Any idea why some of the library would work without issue but other parts would be unresolved?
import sklearn
from sklearn.utils import shuffle
from sklearn import linear_model
import pandas as pd
import numpy as np
df = df[[...]]
x = np.array(df.drop([prediction], 1))
y = np.array(df[prediction])
x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.1)
model = linear_model.LinearRegression()
model.fit(x_train, y_train)
accuracy = model.score(x_test, y_test)
print(accuracy)
print("Coefficient: \n", linear.coef_)
print("Intercept: \n", linear.intercept_)
predictions = linear.predict(x_test)
Solution
For attributes such as .coef_ and .intercept_ .predict, these you need to go about by writing model.predict() / model.coef_ and so on. Could you give this a try?
model = linear_model.LinearRegression()
model.fit(...)
model.coef_
model.intercept_
model.predict(x_test)
should help solve your issue.
Answered By - Kim Hyun Bin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.