Skip to content

[MRG+1] Added sample weight parameter to linearsvc.fit, includes tests and documentation. #6939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 11, 2016

Conversation

imaculate
Copy link
Contributor

@imaculate imaculate commented Jun 24, 2016

Reference Issue

A redo of #6937 from fresh master . Stems from #6862.

What does this implement/fix? Explain your changes.

Any other comments?

@imaculate imaculate mentioned this pull request Jun 24, 2016
@agramfort
Copy link
Member

Look at your history it is still a mess

@imaculate
Copy link
Contributor Author

@agramfort , what do you recommend to fix it?

@maniteja123
Copy link
Contributor

maniteja123 commented Jun 24, 2016

Hi, it seems master is getting merged into the branch and messing up with the history. AFAIK the following is the best method to revert back

git checkout master
# git remote add upstream git://github.com/scikit-learn/scikit-learn.git
git fetch upstream
git merge upstream/master
# Now the master of your fork and scikit learn are on par
git checkout linearsvc_sample_weight
# rebase on top of master. This may give conflicts
git rebase -i master
# solve the conflict manually if any
# git remote add origin git@github.com:imaculate/scikit-learn.git
# force push onto this branch
git push origin linearsvc_sample_weight -f

Cheers.

@imaculate
Copy link
Contributor Author

Thanks @maniteja123 . I have done that, after the last push, it says 'Everything uptodate' .

@maniteja123
Copy link
Contributor

maniteja123 commented Jun 24, 2016

Oh sorry, even I am no expert in this. But looking at the comparison here it seems that your master is ahead of the scikit learn master. Maybe you could first update your local master to be on par with upstream master and then rebase on it.

@TomDLT
Copy link
Member

TomDLT commented Jun 24, 2016

As you have only one commit, you can cherry-pick it from a freshly downloaded master:

# go to your branch
git checkout linearsvc_sample_weight
# always do a backup
git checkout -b linearsvc_sample_weight_back_up
# delete master
git branch -D master
# and download a fresh new version of master
git fetch upstream master:master
# go to master
git checkout master
# delete your branch (you have a backup)
git branch -D linearsvc_sample_weight
# recreate your branch from fresh master
git checkout -b linearsvc_sample_weight
# apply only your last commit
git cherry-pick 8e403d69df5a9de0daf9344e662677dd7abc45ac
# force push
git push -f origin linearsvc_sample_weight

@imaculate imaculate force-pushed the linearsvc_sample_weight branch from 8e403d6 to 94dc0a6 Compare June 26, 2016 15:38
@imaculate
Copy link
Contributor Author

Thanks @TomDLT , I have done that.

unit_weight = np.ones(n_samples)
clf = svm.LinearSVC(random_state=0).fit(X, Y)
clf_unitweight = svm.LinearSVC(random_state=0).fit(X, Y,
sample_weight=unit_weight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow PEP8 indentation. An easy option is to do the .fit on a separate line.

@jnothman
Copy link
Member

You have a testing failure to deal with.

@imaculate
Copy link
Contributor Author

Fixed the above @jnothman

unit_weight = np.ones(n_samples)
clf = svm.LinearSVC(random_state=0).fit(X, Y)
clf_unitweight = svm.LinearSVC(random_state=0).\
fit(X, Y, sample_weight=unit_weight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant just clf_unitweight.fit(...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is okay...

@jnothman
Copy link
Member

LGTM

@jnothman jnothman changed the title A redo of #6937 from fresh master . Stems from #6862.Added sample weight parameter to linearsvc.fit, includes tests and documentation. [MRG+1] Added sample weight parameter to linearsvc.fit, includes tests and documentation. Jun 28, 2016
@@ -177,6 +177,11 @@ def fit(self, X, y):
y : array-like, shape = [n_samples]
Target vector relative to X

sample_weight : array-like, shape = [n_samples], optional
Array of weights that are assigned to individual
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the same alignment as in the other docstrings: all the lines after the parameter first line are indented by four spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am afraid that you got this alignment wrong: you can have a look at the lines right above those that you modified: you documentation line should be aligned the same way as the documentation line on the "y" parameter.

sample_weight : array-like, shape = [n_samples], optional
Array of weights that are assigned to individual
samples. If not provided,
then each sample is given unit weight.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is correct :).

@GaelVaroquaux
Copy link
Member

Aside from the minor comment, this look good to me. Thanks!

@imaculate
Copy link
Contributor Author

@GaelVaroquaux , Done! Thank you. @lesteve should I rename the function?

@jnothman
Copy link
Member

yes, rename the test and we'll merge.

@jnothman
Copy link
Member

thanks!

@jnothman jnothman merged commit 03ec6c9 into scikit-learn:master Jul 11, 2016
@jnothman
Copy link
Member

Thanks. I've updated whats_new in 69e1df8

olologin pushed a commit to olologin/scikit-learn that referenced this pull request Aug 24, 2016
TomDLT pushed a commit to TomDLT/scikit-learn that referenced this pull request Oct 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants