-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression_model.py
More file actions
30 lines (21 loc) · 855 Bytes
/
regression_model.py
File metadata and controls
30 lines (21 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
# Load the cleaned dataset with sentiment
data = pd.read_csv('/path/to/sentiment_IMDB.csv')
# Features and target variable
X = data.drop(['Name', 'Image-src', 'Description', 'Name-href', 'Rating'], axis=1)
y = data['Rating']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize the Linear Regression model
model = LinearRegression()
# Train the model
model.fit(X_train, y_train)
# Make predictions on the testing set
y_pred = model.predict(X_test)
# Compute the Mean Squared Error (MSE)
mse = mean_squared_error(y_test, y_pred)
# Print the MSE
print('Mean Squared Error:', mse)