File size: 877 Bytes
25a0890 | 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 | import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
df = pd.read_csv("normalized_train_dataset_with_train_number.csv")
X = df[["departure_station", "arrival_station", "departure_time", "arrival_time", "day_of_week", "train_type", "distance_km"]]
y = df["train_number"] #Defining features and target
model = LinearRegression() #Initializing the model
model.fit(X, y) # Training the model
weights = model.coef_ #Extracting weights and biases
bias = model.intercept_
feature_names = X.columns
print("Learned Weights:")
for feature, weight in zip(feature_names, weights):
print(f"{feature}: {weight:.4f}")
print(f"\nLearned Bias (Intercept): {bias:.4f}")
y_pred = model.predict(X) # Evaluate the model
mse = mean_squared_error(y, y_pred)
print(f"\nMean Squared Error on Training Data: {mse:.4f}") |