# train_model.py import pandas as pd from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import accuracy_score import joblib # Load the collected data from CSV data = pd.read_csv('wifi_signals.csv') # Features (SignalStrength) and target (Location) X = data[['SignalStrength']] y = data['Location'] # Split the data into training and test sets (80% train, 20% test) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Train a Random Forest Classifier model = RandomForestClassifier() model.fit(X_train, y_train) # Evaluate the model y_pred = model.predict(X_test) accuracy = accuracy_score(y_test, y_pred) print(f'Model Accuracy: {accuracy * 100:.2f}%') # Save the trained model to a file joblib.dump(model, 'wifi_model.pkl')