[scikit-learn] How can i write the birch prediction results to the file

David Nicholson nicholdav at gmail.com
Mon Aug 21 10:41:51 EDT 2017


Ack, should've mentioned you can do:

from sklearn.externals import joblib

since it is a sklearn dependency. That way you won't need to install joblib
separately

On Aug 21, 2017 10:38, "David Nicholson" <nicholdav at gmail.com> wrote:

> Hi Sema,
>
> You can save using pickle from the Python standard library, or using the
> joblib library which is a dependency of sklearn (so you have it already).
>
> The sklearn docs show examples of saving models but it will work for your
> predict results too:
> http://scikit-learn.org/stable/modules/model_persistence.html
>
> You'd just do something like:
> import joblib
> ...
> # your code here
> ...
> birch_predict = brc.predict(X)
> filename = 'predictions'
> joblib.dump(birch_predict, filename)
>
> And you can get the values back into memory with joblib.load
>
> Hth
> --David (list lurker)
>
> On Aug 21, 2017 10:13, "Sema Atasever" <s.atasever at gmail.com> wrote:
>
> Dear scikit-learn developers,
>
> I have a text file where the columns represent the 22 features and the
> rows represent the amino asid . (you can see in the attachment)
>
>
> I want to apply hierarchical clustering to this database usign *sklearn.cluster.Birch
> algorithm.*
>
> There are too many prediction results and it is not possible to see them
> on the screen.
> How can i write the birch prediction results to the file?
>
> I would appreciate if you could advise on some methods.
> Thanks.
>
> *Birch Codes:*
> from sklearn.cluster import Birch
> import numpy as np
>
> X=np.loadtxt(open("C:\class1.txt", "rb"), delimiter=";")
>
> brc = Birch(branching_factor=50, n_clusters=None,
> threshold=0.5,compute_labels=True,copy=True)
>
> brc.fit(X)
>
> centroids = brc.subcluster_centers_
>
> labels = brc.subcluster_labels_
> n_clusters = np.unique(labels).size
> brc.predict(X)
>
> print("\n brc.predict(X)")
> print(brc.predict(X))
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170821/ba3cc581/attachment.html>


More information about the scikit-learn mailing list