2021-04-10 20:54:29 +02:00
|
|
|
import kaggle
|
2021-04-10 16:11:18 +02:00
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
from sklearn import preprocessing
|
|
|
|
|
|
|
|
|
2021-04-10 20:54:29 +02:00
|
|
|
# kaggle
|
|
|
|
kaggle.api.authenticate()
|
|
|
|
kaggle.api.dataset_download_files('timmate/avocado-prices-2020', path='.', unzip=True)
|
|
|
|
|
2021-04-10 16:11:18 +02:00
|
|
|
avocado_with_year = pd.read_csv('avocado-updated-2020.csv')
|
|
|
|
|
|
|
|
new = ['date', 'average_price', 'total_volume', '4046', '4225', '4770', 'total_bags', 'small_bags', 'large_bags', 'xlarge_bags', 'type', 'geography']
|
|
|
|
avocado = avocado_with_year[new]
|
|
|
|
avocado.to_csv("avocado.csv", index=False)
|
|
|
|
avocado = pd.read_csv('avocado.csv')
|
|
|
|
|
|
|
|
avocado_train, avocado_validate, avocado_test = np.split(avocado.sample(frac=1), [int(.6*len(avocado)), int(.8*len(avocado))])
|
|
|
|
|
|
|
|
print("Avocado: ".ljust(20), np.size(avocado))
|
|
|
|
print("Avocado (train) : ".ljust(20), np.size(avocado_train))
|
|
|
|
print("Avocado (validate): ".ljust(20), np.size(avocado_validate))
|
|
|
|
print("Avocado (test) ".ljust(20), np.size(avocado_test))
|
|
|
|
|
|
|
|
avocado.describe(include = 'all')
|
|
|
|
avocado_train.describe(include= 'all')
|
|
|
|
avocado_validate.describe(include = 'all')
|
|
|
|
avocado_test.describe(include = 'all')
|
|
|
|
|
|
|
|
avocado.geography.value_counts()
|
|
|
|
avocado_test.geography.value_counts()
|
|
|
|
avocado_train.geography.value_counts()
|
|
|
|
pd.value_counts(avocado['type']).plot.bar()
|
|
|
|
pd.value_counts(avocado_train['type']).plot.bar()
|
|
|
|
pd.value_counts(avocado_test['type']).plot.bar()
|
|
|
|
avocado['average_price'].hist()
|
|
|
|
avocado_train['average_price'].hist()
|
|
|
|
avocado_validate['average_price'].hist()
|
|
|
|
avocado_test['average_price'].hist()
|
|
|
|
|
|
|
|
num_values = avocado.select_dtypes(include='float64').values
|
|
|
|
scaler = preprocessing.MinMaxScaler()
|
|
|
|
x_scaled = scaler.fit_transform(num_values)
|
|
|
|
num_columns = avocado.select_dtypes(include='float64').columns
|
|
|
|
avocado_normalized = pd.DataFrame(x_scaled, columns=num_columns)
|
|
|
|
for col in avocado.columns:
|
|
|
|
if col in num_columns:
|
|
|
|
avocado[col] = avocado_normalized[col]
|
|
|
|
|
|
|
|
avocado.isnull().sum()
|
|
|
|
avocado.dropna()
|