-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightning website
90 lines (61 loc) · 2.88 KB
/
Lightning website
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import streamlit as st
import pandas as pd
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import metrics
from PIL import Image
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.metrics import r2_score, explained_variance_score, mean_absolute_error
st.write("""
# Danger of Lightning Strikes
Using machine learning to predict the danger of lightning strikes:
""")
image = Image.open(r'C:\Users\eilee\Downloads\lightningpic.jpg')
st.image(image, caption='https://unsplash.com/s/photos/lightning',use_column_width=True)
st.sidebar.header('User Input Parameters')
def user_input_features():
latitude = st.sidebar.slider('Latitude', 30.0, 50.0, 40.0)
longitude = st.sidebar.slider('Longitude', -120.0, -60.0, -80.0)
prcp = st.sidebar.slider('Precipitation levels in mm', 0.0, 100.0, 0.0)
avgtemp = st.sidebar.slider('Temperature in Celsius', -50.0, 50.0, 0.0)
windspeed = st.sidebar.slider('Wind speed in km/h', 0.0, 40.0, 10.0)
data = {'latitude': latitude,
'longitude': longitude,
'prcp': prcp,
'avgtemp': avgtemp,
'windspeed': windspeed}
features = pd.DataFrame(data, index =[0])
return features
df = user_input_features()
#---------------------------------------------------------------------------#
col_names = ['latitude', 'longitude', 'prcp', 'avgtemp', 'windspeed','label']
pima = pd.read_csv(r"C:\Users\eilee\Downloads\allValues.csv", header=0, names = col_names)
feature_names = ['latitude', 'longitude', 'prcp', 'avgtemp', 'windspeed']
X = pima[feature_names] # Features
y = pima.label # Target variable
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=.25,random_state=None)
# instantiate the model (using the default parameters)
logreg = LogisticRegression(solver='liblinear')
# fit the model with data
logreg.fit(X_train,y_train)
#
y_pred=logreg.predict(X_test)
prediction = logreg.predict(df)
prediction_proba = logreg.predict_proba(df)
cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
#-------------------------------------------------------------------------#
st.subheader('User Input Parameters')
st.write(df)
st.subheader('Confusion Matrix:')
st.write(cnf_matrix)
st.subheader('Prediction Probability:')
st.write(prediction_proba)
st.text('The number under the 0 column is the probability of no lightning strikes')
st.text('The number under the 1 column is the probability of lightning strikes')
st.subheader(' ')
if st.button('Extra information'):
st.write('Created by Eileen Chen')
st.write('Project A31')
st.write('Made with streamlit')