-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfire_prediction.py
35 lines (26 loc) · 960 Bytes
/
fire_prediction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Building the regression model from the dataset
FW_Veg_Rem_Combined.csv is a dataset of US wildfires by location, weather, and other attributes
"""
import pandas as pd
from sklearn.linear_model import Ridge
import pickle
# first gather the data we want to train our model on
df = pd.read_csv('FW_Veg_Rem_Combined.csv')
# remove missing data
df = df[df.Temp_pre_7 != -1.0]
df = df[df.Temp_pre_7 != 0.0]
df = df[df.Wind_pre_7 != -1.0]
df = df[df.Wind_pre_7 != 0.0]
df = df[df.Hum_pre_7 != -1.0]
df = df[df.Hum_pre_7 != 0.0]
feature_cols = ['latitude', 'longitude', 'Temp_pre_7', 'Wind_pre_7', 'Hum_pre_7']
X_train = df.loc[:, feature_cols]
y_train = df.loc[:, 'fire_size']
# creating the ridge regression model
model = Ridge(alpha = 3.0)
# fitting the model
model.fit(X_train, y_train)
# Save the trained model as a .sav file
filename = "fire_prediction_model_unscaled.sav"
pickle.dump(model, open(filename, 'wb'))