我已将3个.csv文件加载到pandas数据帧中,然后将某些属性移动到数据字典并生成它的图表。有人可以帮助我为图中的数据运行线性回归吗?
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 :(得分:0)
seaborn中的regplot
可能是您正在寻找的:
import seaborn as sns
#some processing
sns.regplot(x, y, fit_reg=True)
希望它有所帮助。