import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
# Načítanie data zo súboru
data = pd.read_csv('practicals/SCProperties.csv')
# Preprocessing
k = 0
relevant_features = data.corr()['critical_temp'].abs().sort_values(ascending=False)[1:k+1].index.tolist()
X = data[relevant_features] if k > 0 else data.drop('critical_temp', axis=1)
y = data['critical_temp']
# Rozdelenie dát na trénovaciu a testovaciu množinu
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=69)
# Lineárny regresný model
linear = LinearRegression().fit(X_train, y_train)
linear_predictions = linear.predict(X_test)
linear_mse = mean_squared_error(y_test, linear_predictions)
print('Linear Regression RMSE: ', linear_mse**0.5)
# Zobrazenie výsledkov
max_T = max(y_test)
plt.scatter(y_test, linear_predictions)
plt.plot([0, max_T], [0, max_T], 'r--')
plt.title('Linear Regression prediction vs true value')
plt.xlabel('True Values')
plt.ylabel('Predictions')
plt.show()