Skip to content

Instantly share code, notes, and snippets.

View nickinack's full-sized avatar
🌴

Karthik Viswanathan nickinack

🌴
View GitHub Profile
@nickinack
nickinack / f16.py
Last active November 22, 2020 06:07
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
@nickinack
nickinack / f15.py
Last active November 22, 2020 06:08
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:
@nickinack
nickinack / f14.py
Last active November 22, 2020 06:08
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' ]
@nickinack
nickinack / f13.py
Last active November 22, 2020 06:09
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)
@nickinack
nickinack / f12.py
Last active November 22, 2020 06:09
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)
@nickinack
nickinack / f11.py
Last active November 22, 2020 06:09
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.