In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you how to install and use mahout, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Install mahout
Download mahout on the official website of http://mahout.apache.org/. The version downloaded by the editor is mahout-distribution-0.9.tar.gz.
Extract it to the mahout folder
Modify environment variabl
Add to / etc/profile:
Export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$MAHOUT_HOME/lib:$JAVA_HOME/jre/libexport MAHOUT_HOME=/home/Shin/hadoop-1.2.1/mahout/mahout-distribution-0.9export MAHOUT_CONF_DIR=/home/Shin/hadoop-1.2.1/mahout/mahout-distribution-0.9/confexport PATH=$PATH:/home/Shin/hadoop-1.2.1/mahout/mahout-distribution-0.9/binexport HADOOP_CONF_DIR=/home/Shin/hadoop-1.2.1/conf
Then source / etc/profile
The editor invokes the random forest in mahout by calling the linux command in java.
Java calls the linux command
The following API is available:
Process exec (String command) / / execute the specified string command Process exec (String command, String [] envp) / / execute the specified string command Process exec (String command, String [] envp) in a separate process in the specified environment File dir) / / execute the specified string command Process exec (String [] cmdarray) in a separate process with a specified environment and working directory / / execute the specified command and variable Process exec (String [] cmdarray, String [] envp) / / execute the specified command and variable Process exec (String [] cmdarray, String [] envp) in a separate process in the specified environment File dir) / / execute the specified commands and variables in a separate process in the specified environment and working directory
Mahout invokes the command parameters of random forest
Referenc
Http://mahout.apache.org/users/classification/partial-implementation.html
/ generate dataset description file String [] commmandStrings1 = new String [] {"/ home/Shin/hadoop-1.2.1/bin/hadoop", "jar", "/ home/Shin/hadoop-1.2.1/mahout/mahout-distribution-0.9/mahout-core-0.9-job.jar", "org.apache.mahout.classifier.df.tools.Describe", "- p", "citydata/city.txt", "- f", "citydata/city+.info" "- d", "15", "N", "C", "L"} Parameter:-p: training data path-f: output description file path-d: data attribute description The details are as follows: n: NUMERICALC: CATEGORICALL: LABELI: IGNORED data: (citytest.txt) 115 0.85 11 49 230 257 155 231 00 20 54 22 Ozone 1 hour mild pollution 45 0.583 0.583 8 23 144 226 196 19 49 35 23 null excellent 31 0.394 8 16 68 96 46 80 31 28 13 3 null excellent 27 0.779 0.84 16 86 87 61 26 40 11 17 6 10 null excellent 0 000 Null null95 1.441 1.203 11 37 92 177 102 135 79 71 35 39 40 fine particulate matter (PM2.5) 51 0.559 0.563 7 12 74 68 68 52 64 15 17 22 22 fine particulate matter (PM10) 43 0.286 0.365 5 20 52 59 45 43 48 12 16 9 9 null excellent 68 1.178 1.748 14 58 105 94 94 92 26 38 13 10 particulate matter (PM10) 55 0.435 0. 82 11 32 76 94 57 80 53 107 39 59 32 Fine particulate matter (PM2.5) good / / formation decision Forest String [] commmandStrings2 = new String [] {"/ home/Shin/hadoop-1.2.1/bin/hadoop" "jar", "/ home/Shin/hadoop-1.2.1/mahout/mahout-distribution-0.9/mahout-examples-0.9-job.jar", "org.apache.mahout.classifier.df.mapreduce.BuildForest", "- Dmapred.max.split.size=1874231", "- d", "citydata/city.txt", "- ds", "citydata/city+.info", "- sl", "5", "- p", "- t", "100th", "- o" "nsl-forest"} -d: training data file path-ds: data description file path-sl: how many attributes are randomly selected for each node of each number-p: represents partial execution-t: number of trees created-o: output decision forest file path / / use decision forest classification new data String [] commmandStrings3 = new String [] {"/ home/Shin/hadoop-1.2.1/bin/hadoop", "jar" "/ home/Shin/hadoop-1.2.1/mahout/mahout-distribution-0.9/mahout-examples-0.9-job.jar", "org.apache.mahout.classifier.df.mapreduce.TestForest", "- I", "citydata/citytest.txt", "- ds", "citydata/city+.info", "- m", "nsl-forest", "- a", "- mr", "- o", "predictions"} -I: test file path-ds: data description file path-m: decision forest file path-mr: calculate using Hadoop distribution-o: output file path Process process1, process2, process3// Process exec (String [] cmdarray) process1 = Runtime.getRuntime (). Exec (commmandStrings1); process1.waitFor (); process2 = Runtime.getRuntime (). Exec (commmandStrings2); process2.waitFor (); process3 = Runtime.getRuntime (). Exec (commmandStrings3); process3.waitFor ()
Because it is a programmatic call to linux, there is no place to display the output of the console. To get the output of the console, you usually use the
Process.getInputStream ()
However, after using this API, the eclipse editor console does not get any output. Try using other linux commands, and Eg:bin/hadoop dfs-rmr test.txt will get the output.
Accidental use
Process.getErrorStream ()
I can't believe you get the output of mahout.
InputStreamReader ir = new InputStreamReader (process.getErrorStream ()); LineNumberReader input = new LineNumberReader (ir); while ((line = input.readLine ())! = null) {related operation}
Mahout forecast result output
Predictions/citytest.txt.out
The prediction results can be viewed under the terminal.
Bin/hadoop dfs-cat predictions/*
The prediction result is double type 0.0jiao 1.0jol 2.0. However, the view under eclipse is empty, its load to local view is garbled, and it is displayed normally under windows, but there is a space between floating-point numbers. Later, you can see the real display form of data ^ @ 0 ^ @ by editing it with vim under the terminal. ^ @ 0
The solution is as follows
FileReader in = new FileReader ("citytest.txt.out"); BufferedReader bin = new BufferedReader (in); FileWriter out = new FileWriter ("cityout.txt"); String str;while ((str = bin.readLine ())! = null) {char a = str.charAt (1); char b = str.charAt (3); char c = str.charAt (5); String s = Character.toString (a) + Character.toString (b) + Character.toString (c) Out.write (s + "\ n");} in.close (); out.close (); this is all about how to install and use mahout. I hope the above content can help you and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.