forked from Manas-tech/MLrun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.pkl
46 lines (33 loc) · 1.28 KB
/
model.pkl
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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, r2_score
import matplotlib.pyplot as plt
input_csv_path = 'accumulated_data.csv'
df = pd.read_csv(input_csv_path)
# Drop 'dt' column as you did before
df.drop(columns=['dt'], inplace=True)
# Define the features (X) and target variable (y)
X = df.drop(columns=['pm10'])
y = df['pm10']
# 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)
# Create and train the Linear Regression model
model = LinearRegression()
model.fit(X_train, y_train)
# Make predictions on the test set
y_pred = model.predict(X_test)
# Calculate Mean Squared Error and R-squared
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
print(f"Mean Squared Error: {mse}")
print(f"R-squared: {r2}")
# Visualize the predictions vs. actual values
plt.scatter(y_test, y_pred)
plt.xlabel("Actual Values")
plt.ylabel("Predicted Values")
plt.title("Actual vs. Predicted Values")
plt.show()
# Calculate the accuracy percentage
accuracy_percentage = r2 * 100
print(f"Accuracy Percentage: {accuracy_percentage:.2f}%")