This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model: | |
def __init__(self, number_of_selected=2): | |
self.classifier = Pipeline( | |
steps=[("select", SelectKBest(k=number_of_selected)), | |
("clf", LogisticRegression())]) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataset import Dataset | |
from model import Model | |
iris_dataset = Dataset("iris.csv") | |
model = Model() | |
model.fit(iris_dataset) | |
model.save("model.pkl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model: | |
... | |
def fit(self, dataset): | |
self.classifier.fit(dataset.features, dataset.target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
class Dataset: | |
def __init__(self, filename): | |
dataset = pd.read_csv(filename) | |
self.features = dataset[["s-l", "s-w", "p-l", "p-w"]] | |
self.target = dataset["variety"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
dataset = pd.read_csv("iris.csv") | |
features = dataset[["s-l", "s-w", "p-l", "p-w"]] | |
target = dataset["variety"] | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model: | |
def __init__(self): | |
self.classifier = Pipeline( | |
steps=[("select", SelectKBest(k=2)), | |
("clf", LogisticRegression())]) | |
def fit(self, features, target): | |
self.classifier.fit(features, target) | |
def load(self, filename): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
def fit_model(features, target): | |
classifier = Pipeline(steps=[("select", SelectKBest(k=2)), | |
("clf", LogisticRegression())]) | |
classifier.fit(features, target) | |
return classifier | |
def load_model(filename): | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
classifier = fit_model(features, target) | |
save_model(classifier, "model.pkl") | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#file: train.py | |
... | |
classifier = Pipeline(steps=[("select", SelectKBest(k=2)), | |
("clf", LogisticRegression())]) | |
classifier.fit(features, target) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
classifier = load_model("model.pkl") | |
... |
NewerOlder