Skip to content
Permalink
Browse files
Code for predicting accidents
  • Loading branch information
twiningo committed Mar 5, 2021
1 parent ebe325f commit 7b9df1b5ce10a9c8866211c3e9be0f107a482bda
Showing 1 changed file with 84 additions and 0 deletions.
@@ -0,0 +1,84 @@
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import linear_model
import statsmodels.api as sm
import statsmodels.formula.api as smf

df = pd.read_csv(r'C:\Users\ojt98\OneDrive\Desktop\Python\weather_data_24hr.csv')
#df=pd.get_dummies(df, prefix='weather', columns=['weather'])

X=df[["windspeedKPH", "humidity", "avgtempC"]]
y=df[["accidents"]]

lm = linear_model.LinearRegression()
model = lm.fit(X,y)
predictions = lm.predict(X)
#print(predictions[0:5])

print(lm.score(X,y)) ##R^2
arr=lm.coef_
print(arr)

for word in arr:
one=(word[0])

for word in arr:
two=(word[1])

for word in arr:
three=(word[2])



##pull live data into this below...

#accidents=one(windspeedKPH)+ two(humidity)+ three(avgtempC)


# python_sub.py
#mosquitto_pub -h mqtt.dioty.co -p 8883 -u <your user-id> -P <your password> -t <topic> -m <message> -r --cafile ./dioty_ca.crt

import paho.mqtt.client as mqtt
import json, os
from datetime import date, datetime
import time

def on_connect(client, userdata, flags, rc):
if rc==0:
client.connected_flag = True
print("connected OK")
client.subscribe("iot/twiningo")
else:
print("Bad connection Returned code=",rc)

def on_message( client, userdata, msg ):
print('in on_message')
""" callback function for messages received """
topic = msg.topic
data = msg.payload.decode("utf8")
print(topic)
print(data)

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set("iot/twiningo", "JLjsTIe2Ws")
client.tls_set("mqtt.crt")
client.connect("mqtt.coventry.ac.uk", 8883)
client.loop_forever()













0 comments on commit 7b9df1b

Please sign in to comment.