Scikit-Learn



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

Output
(150,)
 
Now, for this regression example, we are going to use the following sample data: 
%matplotlib inline 
import matplotlib.pyplot as plt 
import numpy as np 
rng = np.random.RandomState(35) 
x = 10*rng.rand(40) 
y = 2*x-1+rng.randn(40) 
plt.scatter(x,y); 
Output 
So, we have the above data for our linear regression example. 
Now, with this data, we can apply the above-mentioned steps. 


Scikit-Learn
20 
Choose a class of model 
Here, to compute a simple linear regression model, we need to import the linear regression 
class as follows: 
from sklearn.linear_model import LinearRegression 
Choose model hyperparameters 
Once we choose a class of model, we need to make some important choices which are 
often represented as hyperparameters, or the parameters that must set before the model 
is fit to data. Here, for this example of linear regression, we would like to fit the intercept 
by using the 
fit_intercept
hyperparameter as follows: 
model = LinearRegression(fit_intercept=True) 
model 
Output 
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, 
normalize=False) 
Arranging the data 
Now, as we know that our target variable 
y
is in correct form i.e. a length 
n_samples
array of 1-D. But, we need to reshape the feature matrix 
X
to make it a matrix of size 
[n_samples, n_features].
It can be done as follows: 
X = x[:, np.newaxis] 
X.shape 
Output 
(40, 1) 
Model fitting 
Once, we arrange the data, it is time to fit the model i.e. to apply our model to data. This 
can be done with the help of 

Yüklə 1,92 Mb.

Dostları ilə paylaş:
1   ...   18   19   20   21   22   23   24   25   ...   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ə