Posts

Showing posts with the label scikit-learn

Logistic Regression (tried to implement) but keep getting too accurate model

Image
Clash Royale CLAN TAG #URR8PPP Logistic Regression (tried to implement) but keep getting too accurate model So I've tried to follow the below tutorial and keep getting a 99% accurate algorithm, but I seriously doubt this. i'm trying to predict risk of injury which is highlighted by IntTot below. https://towardsdatascience.com/building-a-logistic-regression-in-python-step-by-step-becd4d56c9c8 Input: Note the column headings are not correct below, first column is index. TotClear BLD_HEIGHT INITIAL_CALL_HOUR TOTAL_NUM_PERSONNEL InjTot TotClearS TOTAL_NUM_PERSONNELS year ALARM_TO_FD 141677 8.316667 0 17 14 0.0 (7.333, 9.683] (7.0, 594.0] 2011 05 314976 21.483333 0 9 4 0.0 (21.0, 28.45] (-0.001, 4.0] 2013 03 215834 5.666667 0 23 4 0.0 NaN NaN 2012 03 318900 13.966667 0 23 20 0.0 (11.867, 14.167] (7.0, 594.0] 2013 01 468452 4.050000 0 5 4 0.0 (-58.834, 7.333] (-0.001...

New to ML trying to use SVM and SVR for 1st time some syntax/transposition errors

Image
Clash Royale CLAN TAG #URR8PPP New to ML trying to use SVM and SVR for 1st time some syntax/transposition errors I am trying to run A SVR on some data I got from yahoo finance. I want to use closing prices of Ethereum to predict next 10-15 days path using a supervised learning method. I have already done autoregressive model (ARIMA) but now I want to try ML techniques like pattern recognition so I start with SVR I am simply running into a problem that I dont know how to convert my data column into a row so that the SVR works...I thought it would be simple but I am new to coding overall...appreciate your help; see below: ''' building a simple model for using machine learning to do pattern recog on stock prices''' import pandas as pd import matplotlib.pyplot as plt import matplotlib.pylab as ply import numpy as np from pandas import DataFrame as df from sklearn.svm import SVR df = pd.read_csv("C:LearningETH.csv", index_col='Date', parse_dates=Tru...

Unsupervised learning clustering 1D array

Image
Clash Royale CLAN TAG #URR8PPP Unsupervised learning clustering 1D array I am faced with the following array: y = [1,2,4,7,9,5,4,7,9,56,57,54,60,200,297,275,243] What I would like to do is extract the cluster with the highest scores. That would be best_cluster = [200,297,275,243] I have checked quite a few questions on stack on this topic and most of them recommend using kmeans. Although a few others mention that kmeans might be an overkill for 1D arrays clustering. However kmeans is a supervised learnig algorithm, hence this means that I would have to pass in the number of centroids. As I need to generalize this problem to other arrays, I cannot pass the number of centroids for each one of them. Therefore I am looking at implementing some sort of unsupervised learning algorithm that would be able to figure out the clusters by itself and select the highest one. In array y I would see 3 clusters as so [1,2,4,7,9,5,4,7,9],[56,57,54,60],[200,297,275,243]. What algorithm would best fit my ...

can't use scikit-learn - “AttributeError: 'module' object has no attribute …”

Image
Clash Royale CLAN TAG #URR8PPP can't use scikit-learn - “AttributeError: 'module' object has no attribute …” I'm trying to follow this tutorial of scikit-learn (linear regression). I've installed scikit through pip install -U scikit-learn , I use python 2.7 and Ubuntu 13.04 pip install -U scikit-learn When I try to run the first lines of code there I get an error and it happens every time I'm trying to run anything with scikit-learn. import pylab as pl import numpy as np from sklearn import datasets, linear_model # Load the diabetes dataset diabetes = datasets.load_diabetes() I get the following: AttributeError: 'module' object has no attribute 'load_diabetes' When I try: regr = linear_model.LinearRegression() I get : AttributeError: 'module' object has no attribute 'LinearRegression' It seems to me that it's either I'm using the package wrong (but I've copied from their tutorial), or I've installed something wrong...

Sklearn method in class

Sklearn method in class I would like to create a class that uses sklearn transformation methods. I found this article and I am using it as an example. sklearn from sklearn import preprocessing from sklearn.base import TransformerMixin def minmax(dataframe): minmax_transformer = preprocessing.MinMaxScaler() return minmax_tranformer class FunctionFeaturizer(TransformerMixin): def __init__(self, scaler): self.scaler = scaler def fit(self, X, y=None): return self def transform(self, X): fv = self.scaler(X) return fv if __name__=="__main__": scaling = FunctionFeaturizer(minmax) df = pd.DataFrame({'feature': np.arange(10)}) df_scaled = scaling.fit(df).transform(df) print(df_scaled) The output is StandardScaler(copy=True, with_mean=True, with_std=True) which is actually the result of the preprocessing.StandardScaler().fit(df) if I use it out of the class. StandardScaler(copy=True, with_mean=True, wit...