commit
0c92c3d87d
@ -0,0 +1,39 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
from sklearn.calibration import LabelEncoder
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
from sklearn.linear_model import LinearRegression
|
||||||
|
|
||||||
|
# Load data from CSV
|
||||||
|
df = pd.read_csv("data\\data_emple.csv")
|
||||||
|
|
||||||
|
category = df.iloc[0:len(df),0].values
|
||||||
|
|
||||||
|
otherData = df.iloc[0:len(df),1:6].values
|
||||||
|
|
||||||
|
print(otherData)
|
||||||
|
|
||||||
|
# Encode the categorical target variable
|
||||||
|
label_encoder = LabelEncoder()
|
||||||
|
category_encoded = label_encoder.fit_transform(category)
|
||||||
|
|
||||||
|
model = LinearRegression()
|
||||||
|
|
||||||
|
model.fit(otherData,category_encoded)
|
||||||
|
|
||||||
|
|
||||||
|
new_data = np.array([224.0,228.49,346.6000000000000,1.1007253886010361,101]).reshape(1, -1)
|
||||||
|
|
||||||
|
# Faites une prédiction avec le modèle entraîné
|
||||||
|
prediction = model.predict(new_data)
|
||||||
|
|
||||||
|
# Affichez la prédiction
|
||||||
|
print("Prédiction:", prediction)
|
||||||
|
|
||||||
|
# Supposons que label_encoder soit l'objet LabelEncoder que vous avez utilisé lors de l'entraînement
|
||||||
|
inverse_prediction = label_encoder.inverse_transform(prediction.astype(int))
|
||||||
|
|
||||||
|
# Affichez la prédiction sous forme de chaîne de caractères
|
||||||
|
print("Prédiction (en chaîne de caractères):", inverse_prediction)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from sklearn.linear_model import LinearRegression
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
df = pd.read_csv("data\\data_emple.csv")
|
||||||
|
distance = df.iloc[0:len(df),1].values.reshape(-1, 1)
|
||||||
|
time = df.iloc[0:len(df),2].values.reshape(-1, 1)
|
||||||
|
|
||||||
|
model = LinearRegression()
|
||||||
|
|
||||||
|
# Entrainement
|
||||||
|
model.fit(time,distance)
|
||||||
|
|
||||||
|
# Afficher les coefficients du modèle
|
||||||
|
print("Coefficients :", model.coef_)
|
||||||
|
print("Intercept :", model.intercept_)
|
||||||
|
|
||||||
|
|
||||||
|
# Supposons que vous avez de nouvelles données pour lesquelles vous voulez faire des prédictions
|
||||||
|
new_time_data = np.array([1000]).reshape(1,-1) # Exemple de nouvelles données pour 'time'
|
||||||
|
|
||||||
|
# Faire des prédictions sur les nouvelles données
|
||||||
|
predicted_distance = model.predict(new_time_data)
|
||||||
|
|
||||||
|
# Afficher les prédictions
|
||||||
|
print("Prédictions de distance :", predicted_distance[0])
|
||||||
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
|||||||
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
|
|
||||||
from sklearn.preprocessing import LabelEncoder
|
|
||||||
|
|
||||||
# Charger les données
|
|
||||||
data = pd.read_csv('data\\data_emple.csv')
|
|
||||||
|
|
||||||
# Encoder les catégories 'category' et 'noteUser'
|
|
||||||
label_encoder = LabelEncoder()
|
|
||||||
data['category'] = label_encoder.fit_transform(data['category'])
|
|
||||||
data['noteUser'] = label_encoder.fit_transform(data['noteUser'])
|
|
||||||
|
|
||||||
# Sélectionner les caractéristiques pour l'entraînement du modèle
|
|
||||||
features = ['category', 'noteUser', 'distance', 'timeOfActivity', 'denivelePositif', 'speedAvg', 'bpmAvg']
|
|
||||||
|
|
||||||
# Diviser les données en ensembles d'entraînement et de test
|
|
||||||
train_data, test_data = train_test_split(data[features], test_size=0.2, random_state=42)
|
|
||||||
|
|
||||||
# Séparer les caractéristiques (X) de la cible (y)
|
|
||||||
X_train, y_train = train_data.drop('noteUser', axis=1), train_data['noteUser']
|
|
||||||
X_test, y_test = test_data.drop('noteUser', axis=1), test_data['noteUser']
|
|
||||||
|
|
||||||
# Créer et entraîner le modèle de régression linéaire
|
|
||||||
model = LinearRegression()
|
|
||||||
model.fit(X_train, y_train)
|
|
||||||
|
|
||||||
# Faire des prédictions sur l'ensemble de test
|
|
||||||
predictions = model.predict(X_test)
|
|
||||||
|
|
||||||
print(predictions)
|
|
||||||
|
|
||||||
# Évaluer le modèle
|
|
||||||
mse = mean_squared_error(y_test, predictions)
|
|
||||||
print(f'Mean Squared Error on Test Data: {mse}')
|
|
Loading…
Reference in new issue