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

Sema Atasever s.atasever at gmail.com
Tue Aug 22 04:24:26 EDT 2017


Dear David,

"joblib.dump" produces a file format with npy extension so I can not open
the file with the notepad editor. I can not see the predictions results
inside the file.

Is there another way to save the prediction results in text format?

Thank you for your help.

On Mon, Aug 21, 2017 at 5:38 PM, 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
>
>
>
>
> _______________________________________________
> 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/20170822/39df903c/attachment.html>


More information about the scikit-learn mailing list