import pandas as pd
import os
import pickle
from sklearn.linear_model import LinearRegression, LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
import numpy as np

PATH = os.getcwd()
data = pd.read_csv(os.path.join(PATH, 'app', 'iris.csv'))


scaler = StandardScaler()
X = data.filter(['Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width'])
y = data['Species']

# Create and fit model
model = Pipeline([('scaler', StandardScaler()),
                 ('classifier', LogisticRegression())])
model.fit(X, y)

# Save model
with open(os.path.join(PATH, 'app', 'classifier.sav'), 'wb') as f:
    pickle.dump(model, f)
