Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
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()