2017-07-19 66 views
1

我已經將3個.csv文件加載到熊貓數據框中,然後將某些屬性移動到數據字典並生成一個圖。有人可以幫助我爲圖中的數據運行線性迴歸?如何在從數據字典獲得的圖上運行線性迴歸

dept_delay_by_airport = small_flights_df.groupby(['ORIGIN_AIRPORT'])['DEPARTURE_DELAY'].mean() 
dept_by_airport = small_flights_df.groupby(['ORIGIN_AIRPORT'])['DEPARTURE_DELAY'].count() 
keys = dept_by_airport.keys() 
data_dict = {k:{} for k in keys} 
for key in keys: 
data_dict[key]['delay_mean'] = dept_delay_by_airport[key] 
data_dict[key]['departures'] = dept_by_airport[key] 
x = [data_dict[k]['departures'] for k in data_dict] 
y = [data_dict[k]['delay_mean'] for k in data_dict] 
plot(x,y,'.') 

The image shows the plot I have obtained and I would like to run a linear regression for this 感謝您抽出寶貴的時間。

回答

0

在seaborn的regplot可能是你要找的東西:

import seaborn as sns 

#some processing 

sns.regplot(x, y, fit_reg=True) 

希望它能幫助。

+0

謝謝!但是我在sklearn中使用了LinearRegression。 –

相關問題