This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# This function calculates my bot's move in connect four algorithm | |
# returned mymove indicates what column to play on | |
# passed variable opponentmove should be the column the opponent just play on | |
# | |
# www.code-wars.com | |
def calculate_my_move (opponentmove): | |
if opponentmove = anything_at_all: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
A small class for Principal Component Analysis | |
@From: http://stackoverflow.com/questions/1730600/principal-component-analysis-in-python | |
@author Denis http://stackoverflow.com/users/86643/denis | |
@dated: April 2010 | |
Usage: | |
p = PCA( A, fraction=0.90 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Thu May 22 20:30:36 2012 | |
http://www.meetup.com/r-enthusiasts/events/65306492/ | |
Mirroring the work that we do in Python. | |
This is the code to import the sales and query data into a Py-Pandas | |
dataframe (with conversion to time series). | |
Author (twitter): @amanqa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import feedparser | |
import nltk | |
from collections import defaultdict | |
#Some userful parameters | |
nitemstoparse = 5 | |
new_words = [] | |
feedurls = [ | |
'http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.utils import check_arrays | |
def mean_absolute_percentage_error(y_true, y_pred): | |
""" | |
Use of this metric is not recommended; for illustration only. | |
See other regression metrics on sklearn docs: | |
http://scikit-learn.org/stable/modules/classes.html#regression-metrics | |
Use like any other metric | |
>>> y_true = [3, -0.5, 2, 7]; y_pred = [2.5, -0.3, 2, 8] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import statsmodels.api as sm | |
#Change next two lines for dataset, such as in | |
#http://vincentarelbundock.github.io/Rdatasets/ | |
data = sm.datasets.get_rdataset('airquality').data | |
class_column = 'Month' | |
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, sharex=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Plotting a categorical variable | |
---------------------------------- | |
`df` is a pandas dataframe with a timeseries index. | |
`df` has a column `categorical` of dtype object, strings and nans, which is a categorical variable representing events | |
---------------------------------- | |
>>> print df[:5] | |
categorical |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Calculation of gini coefficient metric | |
via https://www.kaggle.com/c/ClaimPredictionChallenge/forums/t/703/code-to-calculate-normalizedgini?forumMessageId=5897#post5897 | |
I'm not the author, thant would be Kaggle user Patrick | |
See http://www.rhinorisk.com/Publications/Gini%20Coefficients.pdf | |
""" | |
def gini(actual, pred, cmpcol = 0, sortcol = 1): | |
assert( len(actual) == len(pred) ) | |
all = np.asarray(np.c_[ actual, pred, np.arange(len(actual)) ], dtype=np.float) | |
all = all[ np.lexsort((all[:,2], -1*all[:,1])) ] |
OlderNewer