New answers tagged

0

Using dplyr: R> df %>% group_by(Area) %>% mutate(Goal = cumsum(c(1, diff(Date) > 1))) %>% group_by(Area, Goal) %>% mutate(Goal2 = min(Date), Goal3 = max(Date)) # # A tibble: 8 x 5 # # Groups: Area, Goal [5] # Area Date Goal Goal2 Goal3 # <chr> <date> <dbl> <date> <date> ...


1

I managed to make it work, by combining the city column with the venue categories column into a 2D (numpy) array which can be used by the RandomForestClassifier of sklearn. Example code: import pandas as pd from sklearn.preprocessing import LabelEncoder from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split ...


1

You can try using sklearn's MultiLabelBinarizer (https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MultiLabelBinarizer.html): mlb = MultiLabelBinarizer() mlb.fit(d['IDs']) new_col_names = ["ID_%s" % c for c in mlb.classes_] # Create new DataFrame with transformed/one-hot encoded IDs ids = pd.DataFrame(mlb.fit_transform(d['...


0

Description It is possible to write ASCII text representation of an R object with the use of dput, dump, dget and source. And with this it is possible to preserve the class information Method saving the file to save the file use the dget and/or dump function, and to make sure that the file preserve the class information use the argument control = "all&...


2

The best way to achieve this would be to save the data as an R data file using either save() or saveRDS(): # option 1 save(df, file="data.Rdata") load("data.Rdata") # option 2 saveRDS(df, file="data2.Rds") df <- readRDS("data2.Rds")


0

I am not an expert in geometrics but I found that this function has already been supported by sklearn. So I decided to help you define a generic function. from sklearn.metrics.pairwise import haversine_distances from math import radians import pandas as pd def distance(location1, lat, lon): location1_radian = [radians(_) for _ in location1] location2 = [...


0

what I understand from your code is you are fitting a one-hot encoder on your training set, which may not include all words that appear in your test set. So when you get a new word in your evaluation method, your transformer cannot hash it, and hence throw an error. the easiest way to solve this would be to use the unknown_error argument in one hot encoder ...


0

You can also use max_df and min_df or max_features for tfidfvectorizer apart from sparse array.


0

"I'd like to check if a person in one data frame is in another one." The condition is for both name and first name be present in both dataframes and in the same row. import pandas as pd lst =["Juan","Pedro","Carlos"] lst2=["Cabrera","Olivera","Paredes"] lst3 =["Juan","Pedro&...


0

To answer your first question, I think OneHotEncoder from category_encoders should be up to the job, just set return_df=False to get a numpy array which you could wrap around a sparse matrix. I don't see how that would lead to a memory error unless you were operating in a very limited space. If that is the case maybe you could simply try LabelEncoder, though ...


Top 50 recent answers are included