<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
from sklearn.tree import DecisionTreeRegressor
import statsmodels.stats.api as sm

import math

import pickle

from sklearn.externals import joblib 


data = pd.read_csv("weatherData.csv") 

# print(data.head())

data['burned'] = [i*43560 for i in data['burned']]

#Solves Data outlier problem
data['burned'] = [i if i < np.mean(data['burned']) else np.mean(data['burned'])  for i in data['burned']]
data['burned'] = [i if i > 0 else np.mean(data['burned'])  for i in data['burned']]

data['cause'] = [i if i else 1 for i in data['cause']]
data['cause'] = [i[0] for i in data['cause']]
data['intensity'] = [i if i else 0 for i in data['intensity']]
data['intensity'] = [i[0] for i in data['intensity']]

data['cause'] = data['cause'].astype(float)
data['intensity'] = data['intensity'].astype(float)


X_train, X_test, y_train, y_test = train_test_split(data.iloc[:, data.columns != 'intensity'], data['intensity'], test_size=0.2,  random_state=42)

print(X_test)
print(X_test.shape)


# train_features, test_features, train_labels, test_labels = train_test_split(df_X, df_Y, test_size = 0.2)
print('Training Features Shape:', X_train.shape)
print('Training Labels Shape:', y_train.shape)
print('Testing Features Shape:', X_test.shape)
print('Testing Labels Shape:', y_test.shape)
# Instantiate model with 100 decision trees
rf = RandomForestRegressor(n_estimators=1000, random_state=None,  min_samples_leaf=6, criterion='mae', 
                           bootstrap='True', max_depth=None, min_samples_split=2, max_features='auto', 
                           oob_score=False, n_jobs=1, verbose=0)

# Train the model on training data
rf.fit(X_train, y_train);


# Save the model as a pickle in a file 
joblib.dump(rf, 'randomForest.pkl') 

# Use the forest's predict method on the test data
predictions = rf.predict(X_test)

# Calculate the absolute errors
errors = abs(predictions.round() - y_test)
# Calculate mean absolute percentage error (MAPE)
mape = 100 *(np.mean(errors))/(2*np.mean(y_test))

accuracy = 100 - np.mean(mape)

print('Accuracy Random Forest:', round(accuracy, 2), '%.')<jupyter_output>Accuracy Random Forest: 83.39 %.
{'fraction_non_alphanumeric': 0.13360488798370673, 'fraction_numerical': 0.015885947046843176, 'mean_word_length': 5.329896907216495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '25575', 'license': 'Apache-2.0', 'n_tokens_mistral': 899, 'n_tokens_neox': 824, 'n_words': 231, 'path': 'RandomForest.ipynb', 'repo_name': 'khushbooekhande/CMMPPT', 'size': '2455'}