We predict the number of the passengers on a flight on a month.
Use Cases:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LinearRegression
import seaborn as sns
import os
# Loading dataset
df = sns.load_dataset("flights")
print ("Total entries: ", len(df))
df.head()
df.groupby(["year", "passengers"]).first()
df.groupby("month")['passengers'].sum().plot(kind="bar")
df.groupby("month")['passengers'].max().plot(kind="bar")
print ("Max passenger count: ", max(df.groupby("month")['passengers'].max()))
df.groupby("month")['passengers'].sum().plot(kind="bar")
df.groupby("month")['passengers'].min().plot(kind="bar")
df.groupby(["year"])['passengers'].sum().plot(kind="bar")
df.plot(x="month", y="passengers", kind="line")
df
le = LabelEncoder()
df.month = le.fit_transform(df['month'])
df.head()
features = df.drop(columns=['passengers']).values
labels = df.passengers.values
lm = LinearRegression()
lm.fit(features, labels)
lm.score(features, labels)
print("Predicted passenger count for Jan, 2020: ",lm.predict(np.array([[2020, 1]])))