【SmileMiner:国人李海峰开发的开源统计机器智能与学习引擎】
https://github.com/haifengl/smile【SmileMiner:国人李海峰开发的开源统计机器智能与学习引擎】http://t.cn/RwHYJNdSmileMiner是一个汇集了各种机器学习算法的纯Java函数库,它是自包含的,仅仅需要Java标准库。主要部件为:Smile,-Math,-Data,-Graph,-Interpolation,-NLP。不可多得的Java机器学习库,其文档和示例都挺赞![赞]
SmileMinerSmileMiner (Statistical Machine Intelligence and Learning Engine) is a set of pure Java libraries of various state-of-art machine learning algorithms. SmileMiner is self contained and requires only Java standard library. The major components include
[*]Smile The core machine learning library
[*]SmileMath Mathematical functions (basic, special, kernel, distance, rbf, etc.), sorting, random number generators, optimization, linear algebra, statistical distributions, and hypothesis testing.
[*]SmileData Parsers for arff, libsvm, delimited text, sparse matrix, microarray gene expression data.
[*]SmileGraph Graph algorithms on adjacency list and matrix.
[*]SmileInterpolation One and two dimensional interpolation.
[*]SmileNLP Natural language processing.
[*]SmilePlot Swing-based data visualization library.
SmileMiner is well documented and you can browse the javadoc for more information. Tutorials are available on the project wiki. A basic tutorial is also included at the bottom of this file.To see SmileMiner in action, please download the demo jar file and then run java -jar smile-demo.jar.You can use the libraries through Maven central repository by adding the following to your project pom.xml file. <dependency> <groupId>com.github.haifengl</groupId> <artifactId>smile-core</artifactId> <version>1.0.3</version> </dependency>You can similarily replace artifactId smile-core with smile-math, smile-data, smile-graph, smile-interpolation, smile-nlp, or smile-plot for other modules.SmileMiner implements the following major machine learning algorithms
[*]Classification Support Vector Machines, Decision Trees, AdaBoost, Gradient Boosting, Random Forest, Logistic Regression, Neural Networks, RBF Networks, Maximum Entropy Classifier, KNN, Naïve Bayesian, Fisher/Linear/Quadratic/Regularized Discriminant Analysis.
[*]Regression Support Vector Regression, Gaussian Process, Regression Trees, Gradient Boosting, Random Forest, RBF Networks, OLS, LASSO, Ridge Regression.
[*]Feature Selection Genetic Algorithm based Feature Selection, Ensemble Learning based Feature Selection, Signal Noise ratio, Sum Squares ratio.
[*]Clustering BIRCH, CLARANS, DBScan, DENCLUE, Deterministic Annealing, K-Means, X-Means, G-Means, Neural Gas, Growing Neural Gas, Hierarchical Clustering, Sequential Information Bottleneck, Self-Organizing Maps, Spectral Clustering, Minimum Entropy Clustering.
[*]Association Rule & Frequent Itemset Mining FP-growth mining algorithm
[*]Manifold learning IsoMap, LLE, Laplacian Eigenmap, PCA, Kernel PCA, Probabilistic PCA, GHA, Random Projection
[*]Multi-Dimensional Scaling Classical MDS, Isotonic MDS, Sammon Mapping
[*]Nearest Neighbor Search BK-Tree, Cover Tree, KD-Tree, LSH
[*]Sequence Learning Hidden Markov Model, Conditional Random Field.
[*]Natural Language Processing Sentence Splitter and Tokenizer, Bigram Statistical Test, Phrase Extractor, Keyword Extractor, Stemmer, POS Tagging, Relevance Ranking
Model SerializationYou may notice that none of models supports Java Serializable interface. It is because the exact format is hard to keep stable, class changes can easily make your serialized data unreadable, reading/writing the data in non-Java code is almost impossible. Currently, we suggest XStream to serialize the trained models. XStream is a simple library to serialize objects to XML and back again. XStream is easy to use and doesn't require mappings (actually requires no modifications to objects).Protostuff is a nice alternative that supports forward-backward compatibility (schema evolution) and validation. Beyond XML, Protostuff supports many other formats such as JSON, YAML, protobuf, etc. For some predicitive models, we look forward to supporting PMML (Predictive Model Markup Language), an XML-based file format developed by the Data Mining Group.SmilePlotSmileMiner also has a Swing-based data visualization library SmilePlot, which provides scatter plot, line plot, staircase plot, bar plot, box plot, histogram, 3D histogram, dendrogram, heatmap, hexmap, QQ plot, contour plot, surface, and wireframe. The class PlotCanvas provides builtin functions such as zoom in/out, export, print, customization, etc.SmilePlot requires SwingX library for JXTable. But if your environment cannot use SwingX, it is easy to remove this dependency by using JTable.To use SmilePlot, add the following to dependencies <dependency> <groupId>com.github.haifengl</groupId> <artifactId>smile-plot</artifactId> <version>1.0.2</version> </dependency>Demo Gallery
https://camo.githubusercontent.com/804437c14e211371e3f8c8bb517e6d75c2ba56e0/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d6b7063612d736d616c6c2e706e67Kernel PCAhttps://camo.githubusercontent.com/a99188ce09cf30da7d78d01702911b88e8d90a50/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d69736f6d61702d736d616c6c2e706e67IsoMap
https://camo.githubusercontent.com/cf8f85d9c5bb289ad0d3924905d967d841f07fcf/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d6d64732d736d616c6c2e706e67Multi-Dimensional Scalinghttps://camo.githubusercontent.com/39035f580e9f2bf7b1dfa04832546257d14f0285/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d736f6d2d736d616c6c2e706e67SOM
https://camo.githubusercontent.com/5fbe44fe78341142196e0434554bfb6787158242/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d616e6e2d736d616c6c2e706e67Neural Networkhttps://camo.githubusercontent.com/81aae2742bcc9635039a9df0007741035bc7cc5b/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d73766d2d736d616c6c2e706e67SVM
https://camo.githubusercontent.com/af9c7e30f4d6d391ac6b679fa6f401c82f844c5d/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d6167676c6f6d657261746976652d636c7573746572696e672d736d616c6c2e706e67Agglomerative Clusteringhttps://camo.githubusercontent.com/89c7dc576e45771d749b20c6f2ab6b5e615abc70/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d786d65616e732d736d616c6c2e706e67X-Means
https://camo.githubusercontent.com/24254568949007ba651b2acda125ebcb88e0931f/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d64627363616e2d736d616c6c2e706e67DBScanhttps://camo.githubusercontent.com/2bbd7265a0d69b3f34e10b53a03489d141ee8b3a/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d6e657572616c2d6761732d736d616c6c2e706e67Neural Gas
https://camo.githubusercontent.com/853451eb5204c4903d0b6682a965fdc84ba15a80/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d776176656c65742d736d616c6c2e706e67Wavelethttps://camo.githubusercontent.com/ca7942d092f2f4fe2da11c377924b61dbea05830/687474703a2f2f68616966656e676c2e6769746875622e696f2f736d696c652f67616c6c6572792f736d696c652d64656d6f2d6d6978747572652d736d616c6c2e706e67Exponential Family Mixture
TutorialThis tutorial shows how to use SmileMiner for predictive modeling (classification and regression) from Java code. It includes loading data, training and testing the model, and applying the model.Load DataMost SmileMiner algorithms take simple double[] as input. So you can use your favorite methods or library to import the data as long as the samples are in double arrays. To make the life easier, SmileMiner does provide a couple of parsers for popular data formats, such as Weka's ARFF files, LibSVM's file format, delimited text files, and binary sparse data. These classes are in the package smile.data.parser. The package smile.data.parser.microarray also provides several parsers for microarray gene expression datasets, including GCT, PCL, RES, and TXT files. In the following example, we use the ARFF parser to load the weather dataset:ArffParser arffParser = new ArffParser();arffParser.setResponseIndex(4);AttributeDataset weather = arffParser.parse(this.getClass().getResourceAsStream("/smile/data/weka/weather.nominal.arff"));double[][] x = weather.toArray(new double.size()][]);int[] y = weather.toArray(new int.size()]);
Note that the data file weather.nominal.arff is not included in the release. To try out the example, please just download any arff file from Internet. In the second line, we use setResponseIndex to set the column index (starting at 0) of dependent/response variable. In supervised learning, we need a response variable for each sample to train the model. Basically, it is the y in the mathematical model. For classification, it is the class label. For regression, it is of real value. Without setting it, the data assume no response variable. In that case, the data can be used for testing or unsupervised learning.The parse method can take a URI, File, path string, or InputStream as input argument. And it returns an AttributeDataset object, which is a dataset of a number of attributes. All attribute values are stored as double even if the attribute may be nominal, ordinal, string, or date. The first call of toArray taking a double[][] argument fills the array with all the parsed data and returns it, of which each row is a sample/object. The second call of toArray taking an int array fills it with the class labels of the samples and then returns it.The AttributeDataset.attributes method returns the list of Attribute objects in the dataset. The Attribute object contains the type information (and optional weight), which is needed in some algorithms (e.g. decision trees). The Attribute object also contain variable name and description, which are useful in the output or UI.Similar to ArffParser, we can also use the DelimitedTextParser class to parse plain delimited text files. By default, the parser expects a white-space-separated-values file. Each line in the file corresponds to a row in the table. Within a line, fields are separated by white spaces, each field belonging to one table column. This class can also be used to read other text tabular files by setting delimiter character such ash ','. The file may contain comment lines (starting with '%') and missing values (indicated by placeholder '?'), which both can be parameterized.DelimitedTextParser parser = new DelimitedTextParser();parser.setResponseIndex(new NominalAttribute("class"), 0);AttributeDataset usps = parser.parse("USPS Train", this.getClass().getResourceAsStream("/smile/data/usps/zip.train"));
where the setResponseIndex also take an extra parameter about the attribute of response variable. Because this is a classification problem, we set it a NominalAttribute with name "class". In case of regression, we should use NumericAttribute instead.If your input data contains different types of attributes (e.g. NumericAttribute, NominalAttribute, StringAttribute, DateAttribute, etc), you should pass an array of Attribute[] to the constructor of DelimitedTextParser to indicate the data types of each column. By default, DelimitedTextParser assumes all columns as NumericAttribute.Train The ModelSmileMiner implements a variety of classification and regression algorithms. In what follows, we train a support vector machine (SVM) on the USPS zip code handwriting dataset. The SVM employs a Gaussian kernel and one-to-one strategy as this is a multi-class problem. Different from LibSVM or other popular SVM library, SmileMiner implements an online learning algorithm for training SVM. The method learn trains the SVM with the given dataset for one epoch. The caller may call this method multiple times to obtain better accuracy although one epoch is usually sufficient. Note that after calling learn, we need to call the finish method, which processes support vectors until converge. As it is an online algorithm, the user may update the model anytime by calling learn even after calling the finish method. In the example, we show another way of learning by working on single sample. As shown in the example, we simply call the predict method on a testing sample. Both learn and predict methods are generic for all classification and regression algorithms.DelimitedTextParser parser = new DelimitedTextParser();parser.setResponseIndex(new NominalAttribute("class"), 0);try { AttributeDataset train = parser.parse("USPS Train", this.getClass().getResourceAsStream("/smile/data/usps/zip.train")); AttributeDataset test = parser.parse("USPS Test", this.getClass().getResourceAsStream("/smile/data/usps/zip.test")); double[][] x = train.toArray(new double.size()][]); int[] y = train.toArray(new int.size()]); double[][] testx = test.toArray(new double.size()][]); int[] testy = test.toArray(new int.size()]); SVM<double[]> svm = new SVM<double[]>(new GaussianKernel(8.0), 5.0, Math.max(y)+1, SVM.Multiclass.ONE_VS_ONE); svm.learn(x, y); svm.finish(); int error = 0; for (int i = 0; i < testx.length; i++) { if (svm.predict(testx) != testy) { error++; } } System.out.format("USPS error rate = %.2f%%\n", 100.0 * error / testx.length); System.out.println("USPS one more epoch..."); for (int i = 0; i < x.length; i++) { int j = Math.randomInt(x.length); svm.learn(x, y); } svm.finish(); error = 0; for (int i = 0; i < testx.length; i++) { if (svm.predict(testx) != testy) { error++; } } System.out.format("USPS error rate = %.2f%%\n", 100.0 * error / testx.length);} catch (Exception ex) { System.err.println(ex);}
As aforementioned, tree base methods need the type information of attributes. In the next example, we train an AdaBoost model on the weather dataset.ArffParser arffParser = new ArffParser();arffParser.setResponseIndex(4);AttributeDataset weather = arffParser.parse(this.getClass().getResourceAsStream("/smile/data/weka/weather.nominal.arff"));double[][] x = weather.toArray(new double.size()][]);int[] y = weather.toArray(new int.size()]);AdaBoost forest = new AdaBoost(weather.attributes(), x, y, 200, 4);
In the example, we set the number of trees as 200 and the maximum number of leaf nodes in the trees as 4, which works as a regularization control.Model ValidationIn the example of USPS, we have both train and test datasets. However, we frequently have only a single dataset for building model. For model validation, SmileMiner provide LOOCV (leave-one-out cross validation), cross validation, and bootstrap in the package smile.validation. Besides, the package also has various measures to evaluate classification, regression, and clustering. For example, we have accuracy, fallout, FDR, F-measure (F1 score or F-score), precision, recall, sensitivity, specificity for classification; absolute deviation, MSE, RMSE, RSS for regression; rand index, adjust rand index for clustering. The following is an example how to use LOOCV.double[][] x = weather.toArray(new double.size()][]);int[] y = weather.toArray(new int.size()]);int n = x.length;LOOCV loocv = new LOOCV(n);int error = 0;for (int i = 0; i < n; i++) { double[][] trainx = Math.slice(x, loocv.train); int[] trainy = Math.slice(y, loocv.train); AdaBoost forest = new AdaBoost(weather.attributes(), trainx, trainy, 200, 4); if (y.test] != forest.predict(x.test])) error++;}System.out.println("Decision Tree error = " + error);
Use The Trained ModelAll classifiers in SmileMiner implements the following interface.public interface Classifier<T> { public int predict(T x); public int predict(T x, double[] posteriori);}
To use the trained model, we can apply the method predict on a new sample. Besides just returning class label, many methods (e.g. neural networks) can also output the posteriori probabilities of each class.
页:
[1]