August 2019
Intermediate to advanced
342 pages
9h 35m
English
In the following code snippet, we will see how to implement a simple predictive model based on linear regression, using the linear_model module of scikit-learn, which we will feed with one of the previously used spam message datasets:
import pandas as pdimport numpy as npdf = pd.read_csv('../datasets/sms_spam_perceptron.csv')X = df.iloc[:, [1, 2]].valuesy = df.iloc[:, 0].valuesy = np.where(y == 'spam', -1, 1)from sklearn.linear_model import LinearRegressionlinear_regression = LinearRegression()linear_regression.fit(X,y)print (linear_regression.score(X,y))
To verify the accuracy of the predictions provided by the linear regression model, we can use the score() method, which gives us the measurement of the ...
Read now
Unlock full access