Skip to content

Instantly share code, notes, and snippets.

View gmyrianthous's full-sized avatar

Giorgos Myrianthous gmyrianthous

View GitHub Profile
from sklearn import preprocessing
from sklearn.linear_model import LogisticRegression
# Label encoding
label_encoder = preprocessing.LabelEncoder()
train_Y = label_encoder.fit_transform(train_Y)
# Model training
clf = LogisticRegression()
clf.fit(train_X, train_Y)
>>> import utils
>>> print(utils.multiclass.type_of_target(train_Y))
'multiclass'
from sklearn import preprocessing
label_encoder = preprocessing.LabelEncoder()
train_Y = label_encoder.fit_transform(train_Y)
>>> import utils
>>> print(utils.multiclass.type_of_target(train_Y))
'continuous'
import numpy as np
from sklearn.linear_model import LogisticRegression
train_X = np.array([
[100, 1.1, 0.8],
[200, 1.0, 6.5],
[150, 1.3, 7.1],
[120, 1.2, 3.0],
[100, 1.1, 4.0],
[150, 1.2, 6.8],
Traceback (most recent call last):
File "test.py", line 14, in <module>
clf.fit(train_X, train_Y)
File "/usr/local/lib/python3.7/site-packages/sklearn/linear_model/_logistic.py", line 1347, in fit
check_classification_targets(y)
File "/usr/local/lib/python3.7/site-packages/sklearn/utils/multiclass.py", line 183, in check_classification_targets
raise ValueError("Unknown label type: %r" % y_type)
ValueError: Unknown label type: 'continuous'
SELECT DISTINCT ON (customer_id) customer_id, store_id
FROM rental_example
ORDER BY customer_id, amount;
/*
|customer_id|store_id|
|-----------|--------|
| 58 | 2 |
| 100 | 6 |
*/
SELECT DISTINCT ON (customer_id) customer_id, store_id
FROM rental;
/*
|customer_id|store_id|
|-----------|--------|
| 58 | 2 |
| 100 | 4 |
*/
SELECT DISTINCT(customer_id), store_id
FROM rental_example;
/*
|customer_id|store_id|
|-----------|--------|
| 100 | 4 |
| 100 | 6 |
| 58 | 2 |
*/
@gmyrianthous
gmyrianthous / select_distinct_example.sql
Created September 4, 2022 13:28
Select distinct customers and stores
SELECT DISTINCT customer_id, store_id
FROM rental_example;
/*
|customer_id|store_id|
|-----------|--------|
| 100 | 4 |
| 100 | 6 |
| 58 | 2 |
*/