Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Update sklearn_transformers.py #4

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions my_custom_sklearn_transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .sklearn_transformers import DropColumns
from .coding import Coding
from .decoding import Decoding
26 changes: 26 additions & 0 deletions my_custom_sklearn_transforms/coding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin


# All sklearn Transforms must have the `transform` and `fit` methods
class Coding(BaseEstimator, TransformerMixin):
def __init__(self, p):
self.p = p

def fit(self):
return self.p

def transform(self):
self.p1 = np.array([])
for i in range(0,len(self.p)):
if self.p[i] == "EXCELENTE":
self.p1 = np.append(self.p1, 1)
if self.p[i] == "MUITO_BOM":
self.p1 = np.append(self.p1, 2)
if self.p[i] == "HUMANAS":
self.p1 = np.append(self.p1, 3)
if self.p[i] == "EXATAS":
self.p1 = np.append(self.p1, 4)
if self.p[i] == "DIFICULDADE":
self.p1 = np.append(self.p1, 5)
return np.ravel(self.p1)
26 changes: 26 additions & 0 deletions my_custom_sklearn_transforms/decoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import numpy as np
from sklearn.base import BaseEstimator, TransformerMixin


# All sklearn Transforms must have the `transform` and `fit` methods
class Decoding(BaseEstimator, TransformerMixin):
def __init__(self, p):
self.p = p

def fit(self):
return self.p

def transform(self):
self.p1 = np.array([])
for i in range(0,len(self.p)):
if self.p[i] <= 1.0:
self.p1 = np.append(self.p1, "EXCELENTE")
if self.p[i] == 2.0:
self.p1 = np.append(self.p1, "MUITO_BOM")
if self.p[i] == 3.0:
self.p1 = np.append(self.p1, "HUMANAS")
if self.p[i] == 4.0:
self.p1 = np.append(self.p1, "EXATAS")
if self.p[i] >= 5.0:
self.p1 = np.append(self.p1, "DIFICULDADE")
return self.p1
12 changes: 10 additions & 2 deletions my_custom_sklearn_transforms/sklearn_transformers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# All sklearn Transforms must have the `transform` and `fit` methods
from sklearn.base import BaseEstimator, TransformerMixin


Expand All @@ -8,9 +9,16 @@ def __init__(self, columns):

def fit(self, X, y=None):
return self

def transform(self, X):
# Primeiro realizamos a cópia do dataframe 'X' de entrada
data = X.copy()
# Retornamos um novo dataframe sem as colunas indesejadas
return data.drop(labels=self.columns, axis='columns')
data = data.drop(labels=self.columns, axis='columns')
data = data.dropna(axis=0, subset=["NOTA_GO"])
df = data[['NOTA_DE' , 'NOTA_EM' , 'NOTA_MF' , 'NOTA_GO']]
data['MEDIA'] = df.mean(axis=1)
data['SOMA'] = df.sum(axis=1)
df = data[['NOTA_DE' , 'NOTA_EM', 'NOTA_GO']]
data['MEDIA_HUMANAS'] = df.mean(axis=1)
return data