`

Jubatus: Classify Example

 
阅读更多

1.create a mvn project with pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>fifo</groupId>
	<artifactId>jubatusTest</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<java.source.level>1.7</java.source.level>
		<java.target.level>1.7</java.target.level>
		<maven.compiler.target>1.7</maven.compiler.target>
		<maven.compiler.source>1.7</maven.compiler.source>

		<slf4j.version>1.6.2</slf4j.version>
		<log4j.version>1.2.17</log4j.version>
	</properties>

	<repositories>
		<repository>
			<id>jubat.us</id>
			<name>Jubatus Repository for Maven</name>
			<url>http://download.jubat.us/maven</url>
		</repository>
	</repositories>

	<dependencies>
		<dependency>
			<groupId>us.jubat</groupId>
			<artifactId>jubatus</artifactId>
			<version>0.7.1</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-shade-plugin</artifactId>
					<version>2.3</version>
					<executions>
						<execution>
							<phase>package</phase>
							<goals>
								<goal>shade</goal>
							</goals>
						</execution>
					</executions>
				</plugin>

			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

 

2. create a class

package jubatusTest;

import java.util.Arrays;
import java.util.List;

import us.jubat.classifier.ClassifierClient;
import us.jubat.classifier.EstimateResult;
import us.jubat.classifier.LabeledDatum;
import us.jubat.common.Datum;

public class GenderMain {

    private static Datum makeDatum(String hair, String top, String bottom, double height) {
	return new Datum().addString("hair", hair).addString("top", top).addString("bottom", bottom)
		.addNumber("height", height);
    }

    private static LabeledDatum makeTrainDatum(String label, String hair, String top, String bottom, double height) {
	return new LabeledDatum(label, makeDatum(hair, top, bottom, height));
    }

    public static void main(String[] args) throws Exception {
	String host = "127.0.0.1";
	int port = 9199;
	String name = "test";

	ClassifierClient client = new ClassifierClient(host, port, name, 1);

	LabeledDatum[] trainData = { //
	makeTrainDatum("male", "short", "sweater", "jeans", 1.70),
		makeTrainDatum("female", "long", "shirt", "skirt", 1.56),
		makeTrainDatum("male", "short", "jacket", "chino", 1.65),
		makeTrainDatum("female", "short", "T shirt", "jeans", 1.72),
		makeTrainDatum("male", "long", "T shirt", "jeans", 1.82),
		makeTrainDatum("female", "long", "jacket", "skirt", 1.43), };

	client.train(Arrays.asList(trainData));

	Datum[] testData = { //
	makeDatum("short", "T shirt", "jeans", 1.81), makeDatum("long", "shirt", "skirt", 1.50), };

	List<List<EstimateResult>> results = client.classify(Arrays.asList(testData));

	for (List<EstimateResult> result : results) {
	    for (EstimateResult r : result) {
		System.out.printf("%s %f\n", r.label, r.score);
	    }
	    System.out.println();
	}

	System.exit(0);
    }
}

 

and configure file gender.json

{
  "method": "AROW",
  "converter": {
    "num_filter_types": {},
    "num_filter_rules": [],
    "string_filter_types": {},
    "string_filter_rules": [],
    "num_types": {},
    "num_rules": [],
    "string_types": {
      "unigram": { "method": "ngram", "char_num": "1" }
    },
    "string_rules": [
      { "key": "*", "type": "unigram", "sample_weight": "bin", "global_weight": "bin" }
    ]
  },
  "parameter": {
    "regularization_weight" : 1.0
  }
}

 

 

3.start Jubatus standlone server

#source /opt/jubatus/profile
#jubaclassifier -f /path/to/gender.json

 

4.run GenderMain  in eclipse

the result is

female -0.081500
male 0.474875

female 0.491617
male -0.336581

 

 

 

 

References

http://jubat.us/en/tutorial/classifier.html

 http://jubat.us/en/tutorial/classifier_java.html

分享到:
评论

相关推荐

    storm-jubatus:Storm和jubatus之间的中间件

    Storm-jubatus 支持的算法 求解器类型 Jubatus算法客户端 用例 回归 回归客户端 对于回归问题 推荐人 推荐客户端 推荐 如何使用 public class JubatusTrainTopology { public static void main ( String [] args )...

    jubaenv:Jubatus 环境切换器

    eval "$(~/.jubaenv/bootstrap)"用法列出所有可用的 Jubatus 版本: $ jubaenv install -l安装 Jubatus: $ jubaenv install 0.6.3列出安装的 Jubatus 版本: $ jubaenv shell0.5.4 0.6.3为当前 shell 切换 Jubatu

    分布式在线机器学习框架Jubatus.zip

    Jubatus 是一个分布式处理框架和机器学习库,包含以下功能:在线机器学习库,包括:分类、聚合和推荐fv_converter: 数据预处理(用自然语言)在线机器学习框架,支持容错 标签:Jubatus

    jubatus-node-client:适用于Node.js的Jubatus客户端(非官方)

    jubatus-node-client 适用于Node.js的Jubatus客户端(非官方) 用法 另请参阅 分类器 const jubatus = require ( "jubatus" ) ; const classifier = new jubatus . classifier . client . Classifier ( 9199 , ...

    jubamgr:Jubatus 管理工具

    朱巴图斯经理和提出的新流程管理工具的原型实现...要求朱巴图斯 0.6.0+ Jubatus Python 客户端 0.6.0+用法 $ jubavisor -z localhost:2181$ jubamgr start server server01$ jubamgr stop server server01执照LGPL 2.1

    PyPI 官网下载 | embedded_jubatus-1.1.0.tar.gz

    资源来自pypi官网。 资源全名:embedded_jubatus-1.1.0.tar.gz

    mpio:具有完全多线程事件循环实现的 C++ 多用途并行 IO 框架

    请参阅 此 frsyuki/mpio 存储... 但是多亏了一个名为的开源项目,mpio 库被维护为jubatus-mpio 。 我建议改为检查存储库: 如果您正在寻找 RPC (msgpack-rpc-cpp),这里是jubatus-msgpack-rpc/cpp : 谢谢,古桥贞行

Global site tag (gtag.js) - Google Analytics