使用Mahout为布尔型数据生成推荐内容
Generating Recommendations with mahout for Boolean data sets (data sets with no preference value)
关于在Spark MLlib中基于布尔型数据集推荐可参考:Spark MLlib中的协同过滤
通过指定alpha:是一个针对于隐性反馈 ALS 版本的参数,这个参数决定了偏好行为强度的基准。
val alpha = 0.01
val model = ALS.trainImplicit(ratings, rank, numIterations, 0.01, alpha)
参考:http://spark.apache.org/docs/latest/mllib-collaborative-filtering.html
Craig Andrews » Best way to use HttpClient in Android
Google不鼓励使用HttpClient,更喜欢使用HttpURLConnection和HttpsURLConnection。
Many Android applications access the Internet resources over HTTP (and my projects are no exception). There are 2 common ways to do that: use Apache HttpClient 4.x (which is included in Android) or use HttpURLConnection (from Java). Google stated in a September 29, 2011 blog post that they prefer you use HttpURLConnection, but many apps and a large number of Java libraries already use HttpClient and won’t be changing soon (if ever). So HttpClient is here to stay.
With that in mind, the performance and footprint of HttpClient can vary widely based on how its set up. Here are my recommendations:
- Always use one HttpClient instance for your entire application. HttpClient is not free to instantiate – each additional instance takes time to create and uses more memory. However, more importantly, using one instance allows HttpClient to pool and reuse connections along with other optimizations that can make big differences in how your application performs.
- Use a thread safe connection manager. If you’re using one global HttpClient, it will be accessed by multiple threads concurrently – so if you don’t use a thread safe connection manager, Bad Things will happen.
- Use Android’s android.net.SSLCertificateSocketFactory and android.net.SSLSessionCacheif they’re available. Using these instead of the base HttpClient SSLSocketFactorywill reduce round trips when connecting to the same https site multiple times, making your application feel faster.
- Set the user agent to something useful. That way, the server’s logs will be far more useful, which may save you (or someone else) a lot of time later if (when) a problem occurs.
With all that said, here’s how I get my global HttpClient instance. This code should work on all Android versions (it should even work all the way back to 1.0 – if anyone cares). I use Google Guice‘s Provider interface and injection to get the application, but you can easily adopt this to a form that doesn’t use Guice.
[HttpClient]HTTPClient PostMethod 中文乱码问题解决方案(2种) - 追竹 - 博客频道 - CSDN.NET
一、在调用PostMethod方法时设置字符编码:
- PostMethod postMethod = new PostMethod(
- "http://127.0.0.1:8080/HttpClientServer/login.do");
- postMethod.getParams(). setParameter( HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
二、重载PostMethod的getRequestCharSet()方法, 返回我们需要的编码(字符集)名称, 就可以解决 UTF-8 或者其它非默认编码提交 POST 请求时的乱码问题了.
- //Inner class for UTF-8 support
- public static class UTF8PostMethod extends PostMethod{
- public UTF8PostMethod(String url){
- super(url);
- }
- @Override
- public String getRequestCharSet() {
- //return super.getRequestCharSet();
- return "utf-8";
- }
- }
- PostMethod postMethod = new UTF8PostMethod(
- "http://127.0.0.1:8080/HttpClientServer/login.do");
三、最后服务器端要配合客户端,设置下编码字符集:
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- //解决中文乱码问题,此步不可少
- request.setCharacterEncoding("UTF-8");
- response.setContentType("text/html");
- response.setCharacterEncoding("UTF-8");
- PrintWriter out = response.getWriter();
- String username = (String) request.getParameter("username");
- String password = (String) request.getParameter("password");
- System.out.println("******************** doPost被执行了 ********************");
- System.out.println("您的请求参数为:/tusername:" + username + "/tpassword:"
- + password);
- out.print("您的请求参数为:/tusername:" + username + "/tpassword:" + password);
- out.flush();
- out.close();
- }