Skip to content

Instantly share code, notes, and snippets.

@nmayorov
nmayorov / hyp1f1_decimal.py
Created January 24, 2016 10:13
Compute hyp1f1 using Taylor series with help of Python' Decimal class
from decimal import Decimal, getcontext
import numpy as np
from math import isfinite
EPS = np.finfo(float).eps
class ComplexDecimal(object):
def __init__(self, real, imag):
@nmayorov
nmayorov / fs_communities_and_crimes.py
Created December 1, 2015 23:09
Feature selection on Communities and Crime dataset
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from sklearn.preprocessing import Imputer
from sklearn.feature_selection import (
SelectKBest, MutualInfoSelector, f_regression)
from sklearn.linear_model import RidgeCV
from sklearn.model_selection import cross_val_score
data = pd.read_csv('communities.data', header=None)
@nmayorov
nmayorov / feature_selection_rfe.py
Created November 30, 2015 22:30
RFE vs. MutualInfoSelector
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import load_digits
from sklearn.feature_selection import RFE, MutualInfoSelector
from sklearn.preprocessing import minmax_scale
from sklearn.svm import LinearSVC
from sklearn.model_selection import cross_val_score
digits = load_digits()
X = minmax_scale(digits.data)
@nmayorov
nmayorov / feature_selection_rf.py
Created November 30, 2015 21:30
Feature selection for RF
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_diabetes, load_boston
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import cross_val_score
from sklearn.feature_selection import (SelectKBest, MutualInfoSelector,
f_classif, f_regression)
from sklearn.pipeline import make_pipeline
@nmayorov
nmayorov / discrete_bvp.ipynb
Last active November 30, 2015 16:34
Solving a discrete boundary-value problem in scipy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nmayorov
nmayorov / feature_selection_pipeline.py
Created November 26, 2015 13:09
Comparison of different feature selection methods with pipeline
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import (load_digits, load_breast_cancer,
load_diabetes, load_boston)
from sklearn.linear_model import RidgeCV
from sklearn.preprocessing import minmax_scale
from sklearn.model_selection import cross_val_score
from sklearn.feature_selection import (SelectKBest, MutualInfoSelector,
f_classif, f_regression)
from sklearn.svm import LinearSVC
@nmayorov
nmayorov / feature_selection_comparison.py
Created November 25, 2015 22:49
Comparison of different feature selection methods
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import (load_digits, load_breast_cancer,
load_diabetes, load_boston)
from sklearn.linear_model import RidgeCV
from sklearn.preprocessing import minmax_scale
from sklearn.model_selection import cross_val_score
from sklearn.feature_selection import (SelectKBest, MutualInfoSelector,
f_classif, f_regression)
from sklearn.svm import LinearSVC
@nmayorov
nmayorov / robust_regression.ipynb
Last active March 2, 2022 06:46
Robust nonlinear regression in scipy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nmayorov
nmayorov / bundle_adjustment_scipy.ipynb
Last active September 19, 2021 02:52
Large scale bundle adjustment in scipy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nmayorov
nmayorov / rosenbrock_leastsqbound.py
Created June 26, 2015 15:56
leastsqbound on Rosenbrock function with a single bound
from __future__ import print_function
import numpy as np
from leastsqbound import leastsqbound
def fun(x):
return np.array([10 * (x[1] - x[0]**2), (1 - x[0])])