python script fotr dockerfile added

This commit is contained in:
patrycjalazna 2021-04-10 16:11:18 +02:00
parent f35048a86a
commit 6a40cad4c8

47
avocado-preprocessing.py Normal file
View File

@ -0,0 +1,47 @@
import pandas as pd
import numpy as np
from sklearn import preprocessing
avocado_with_year = pd.read_csv('avocado-updated-2020.csv')
avocado_with_year
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()