Scikit-Learn


fit() method as follows:  model.fit(X, y)  Output



Yüklə 1,92 Mb.
Pdf görüntüsü
səhifə23/124
tarix23.02.2023
ölçüsü1,92 Mb.
#101394
1   ...   19   20   21   22   23   24   25   26   ...   124
sklearn

fit()
method as follows: 
model.fit(X, y) 
Output 
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, 


Scikit-Learn
21 
normalize=False) 
In Scikit-learn, the 
fit()
process have some trailing underscores.
For this example, the below parameter shows the slope of the simple linear fit of the data: 
model.coef_
Output 
array([1.99839352]) 
The below parameter represents the intercept of the simple linear fit to the data: 
model.intercept_ 
Output 
-0.9895459457775022 
Applying the model to new data 
After training the model, we can apply it to new data. As the main task of supervised 
machine learning is to evaluate the model based on new data that is not the part of the 
training set. It can be done with the help of 
predict()
method as follows: 
xfit = np.linspace(-1, 11) 
Xfit = xfit[:, np.newaxis] 
yfit = model.predict(Xfit) 
plt.scatter(x, y) 
plt.plot(xfit, yfit); 
Output 


Scikit-Learn
22 
Complete working/executable example 
%matplotlib inline 
import matplotlib.pyplot as plt 
import numpy as np 
import seaborn as sns 
iris = sns.load_dataset('iris') 
X_iris = iris.drop('species', axis = 1) 
X_iris.shape 
y_iris = iris['species'] 
y_iris.shape 
rng = np.random.RandomState(35) 
x = 10*rng.rand(40) 
y = 2*x-1+rng.randn(40) 
plt.scatter(x,y); 
from sklearn.linear_model import LinearRegression 
model = LinearRegression(fit_intercept=True) 
model 
X = x[:, np.newaxis] 
X.shape 
model.fit(X, y) 


Scikit-Learn
23 
model.coef_
model.intercept_ 
xfit = np.linspace(-1, 11) 
Xfit = xfit[:, np.newaxis] 
yfit = model.predict(Xfit) 
plt.scatter(x, y) 
plt.plot(xfit, yfit); 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   19   20   21   22   23   24   25   26   ...   124




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə