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 numpy as np | |
import matplotlib.pyplot as plt | |
import random | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn import preprocessing | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.ensemble import RandomForestRegressor | |
from sklearn.linear_model import LinearRegression | |
from sklearn import metrics |
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
df1 = pd.read_csv("communities.data" , header=None) | |
def read_header(filename): | |
''' | |
Given a filename containing headers, extract the headers and assign it to df | |
''' | |
header_list = [] | |
with open(filename) as f: | |
for line in f: | |
if "@attribute" in line: |
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 drop_columns(columns , df): | |
''' | |
Given dataframe , returns updated df with removed colums | |
''' | |
for i in columns: | |
df = df.drop(i , axis=1) | |
return df | |
drop_list = ['state' , 'county' , 'community' , 'communityname' , 'fold' ] |
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
x = df1.drop("ViolentCrimesPerPop", axis=1) | |
y = df1["ViolentCrimesPerPop"] | |
x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.8, random_state=24) | |
print(x_train.shape , y_train.shape) | |
print(x_test.shape , y_test.shape) |
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 fitness_func(chromosome): | |
columns = [] | |
for i in range(len(x_train.columns)): | |
if i in chromosome: | |
columns.append(x_train.columns[i]) | |
dist.append(columns) | |
training_set = x_train[columns] | |
print(training_set) | |
test_set = x_test[columns] | |
lg = LinearRegression().fit(training_set.values, y_train.values) |
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 FeatureSolver(AbstractSolver): | |
def __init__( | |
self, | |
problem_type=float, | |
fitness_func= lambda a : fitness_func(a), | |
pop_cnt: int = 40, | |
gene_size: int = 50, | |
max_gen: int = 2, | |
mutation_ratio: float = 0.2, | |
selection_ratio: float = 0.2, |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder