ulysse commited on
Commit
5689d12
·
1 Parent(s): ee3915f

Upgrade to RFR model

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
  from sklearn.linear_model import LinearRegression
 
5
  from sklearn.datasets import fetch_california_housing
6
 
7
  def trainme(MedInc, HouseAge, AveRooms, AveBedrms, Population, AveOccup, Latitude, Longitude, Price):
@@ -21,9 +22,9 @@ def trainme(MedInc, HouseAge, AveRooms, AveBedrms, Population, AveOccup, Latitud
21
  X = housing_df.drop('Price', axis=1).to_numpy()
22
 
23
  #create a machine learning model and train it
24
- lineareg = LinearRegression()
25
- lineareg.fit(X,y)
26
-
27
  #Create a redable/clean feature list
28
  clean_features = ['Median income',
29
  'Median house age',
@@ -39,12 +40,12 @@ def trainme(MedInc, HouseAge, AveRooms, AveBedrms, Population, AveOccup, Latitud
39
  explainer = lime_tabular.LimeTabularExplainer(X, mode="regression", feature_names=clean_features)
40
 
41
  #Create the expl
42
- explanation = explainer.explain_instance(X[0], lineareg.predict, num_features=len(housing.feature_names))
43
  listing = explanation.as_list()
44
  #explanation.show_in_notebook(show_table=True)
45
 
46
  #Get pred and actual scores
47
- Pred_value = lineareg.predict(X[0].reshape(1,-1))*100000
48
  Actual_value = y[0]*100000
49
  Error_rate = ((Pred_value - Actual_value)/Actual_value) *100
50
 
 
2
  import pandas as pd
3
  import numpy as np
4
  from sklearn.linear_model import LinearRegression
5
+ from sklearn.ensemble import RandomForestRegressor
6
  from sklearn.datasets import fetch_california_housing
7
 
8
  def trainme(MedInc, HouseAge, AveRooms, AveBedrms, Population, AveOccup, Latitude, Longitude, Price):
 
22
  X = housing_df.drop('Price', axis=1).to_numpy()
23
 
24
  #create a machine learning model and train it
25
+ regressor = RandomForestRegressor(n_estimators = 100, random_state = 0)
26
+ regressor.fit(X,y)
27
+
28
  #Create a redable/clean feature list
29
  clean_features = ['Median income',
30
  'Median house age',
 
40
  explainer = lime_tabular.LimeTabularExplainer(X, mode="regression", feature_names=clean_features)
41
 
42
  #Create the expl
43
+ explanation = explainer.explain_instance(X[0], regressor.predict, num_features=len(housing.feature_names))
44
  listing = explanation.as_list()
45
  #explanation.show_in_notebook(show_table=True)
46
 
47
  #Get pred and actual scores
48
+ Pred_value = regressor.predict(X[0].reshape(1,-1))*100000
49
  Actual_value = y[0]*100000
50
  Error_rate = ((Pred_value - Actual_value)/Actual_value) *100
51