Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
machine-learnig/random forrest.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (21 sloc)
919 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import necessary libraries | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.metrics import accuracy_score | |
# Load your dataset | |
file_path = 'C:/Users/wilso/OneDrive/Desktop/uk_renewable_energy.csv' | |
df = pd.read_csv(file_path) | |
X = df.iloc[:, :-1] | |
y = df.iloc[:, -1] | |
# Split the dataset 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 a Random Forest classifier | |
rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42) | |
# Train the classifier on the training data | |
rf_classifier.fit(X_train, y_train) | |
# Make predictions on the testing data | |
y_pred = rf_classifier.predict(X_test) | |
# Evaluate the accuracy of the classifier | |
accuracy = accuracy_score(y_test, y_pred) | |
print(f"Accuracy: {accuracy:.2f}") |