前言
以下为近期对矩阵分解到银子分解机研究的总结。本来想把公式都打进去,无奈对mathjax实在不熟,直接上图吧。
1. SVD
$R=PSV$
其中$S$为对角矩阵
2. MF(LMF)
$R=P^T*Q$
BasicMF:
loss:$ \sum_{i=1}^n $

Python、Spark、ML、DL、推荐
前言
以下为近期对矩阵分解到银子分解机研究的总结。本来想把公式都打进去,无奈对mathjax实在不熟,直接上图吧。
$R=PSV$
其中$S$为对角矩阵
$R=P^T*Q$
BasicMF:
loss:$ \sum_{i=1}^n $
前言
以下为对实际生产环境中ItemCF、UserCF召回策略的总结
1 | 1.item , (user,score) |
1 | -1.user , (item,score) |
1 | 1.item , user |
注:
1 | def cal_score(line): |
将user , list[(item,score,sqrt_item)] 换为 item , list[(user,score,sqrt_user)] 即可
Python 正则表达式的使用经验
http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html
http://www.jb51.net/tools/zhengze.html
1 | pattern = re.compile(r'Regulator') |
Python ConfigParser的使用经验
1 | -read(filename) 直接读取ini文件内容 |
1 | -add_section(section) 添加一个新的section |
3.基本例子
[sec_a]
a_key1 = 20
a_key2 = 10
[sec_b]
b_key1 = 121
b_key2 = b_value2
b_key3 = $r
b_key4 = 127.0.0.1
1 | #!/usr/bin/env python |
得到终端输出:
sections: [‘sec_b’, ‘sec_a’]
options: [‘a_key1’, ‘a_key2’]
sec_a: [(‘a_key1’, “i’m value”), (‘a_key2’, ‘22’)]
value for sec_a’s a_key1: i’m value
value for sec_a’s a_key2: 22
更新后的test.conf
[sec_b]
b_newkey = new-value
b_key4 = 127.0.0.1
b_key1 = 121
b_key2 = b_value2
b_key3 = new-$r
[sec_a]
a_key1 = i’m value
a_key2 = 22
[a_new_section]
new_key = new_value
Python的ConfigParser Module中定义了3个类对INI文件进行操作。分别是RawConfigParser、ConfigParser、SafeConfigParser。RawCnfigParser是最基础的INI文件读取类,ConfigParser、SafeConfigParser支持对%(value)s变量的解析。
设定配置文件test2.conf
[portal]
url = http://%(host)s:%(port)s/Portal
host = localhost
port = 8080
使用RawConfigParser:1
2
3
4
5
6
7
8
9
10
11import ConfigParser
cf = ConfigParser.RawConfigParser()
print "use RawConfigParser() read"
cf.read("test2.conf")
print cf.get("portal", "url")
print "use RawConfigParser() write"
cf.set("portal", "url2", "%(host)s:%(port)s")
print cf.get("portal", "url2")
得到终端输出:
use RawConfigParser() read
http://%(host)s:%(port)s/Portal
use RawConfigParser() write
%(host)s:%(port)s
改用ConfigParser:1
2
3
4
5
6
7
8
9
10
11import ConfigParser
cf = ConfigParser.ConfigParser()
print "use ConfigParser() read"
cf.read("test2.conf")
print cf.get("portal", "url")
print "use ConfigParser() write"
cf.set("portal", "url2", "%(host)s:%(port)s")
print cf.get("portal", "url2")
得到终端输出:
use ConfigParser() read
http://localhost:8080/Portal
use ConfigParser() write
localhost:8080
改用SafeConfigParser:1
2
3
4
5
6
7
8
9
10
11import ConfigParser
cf = ConfigParser.SafeConfigParser()
print "use SafeConfigParser() read"
cf.read("test2.conf")
print cf.get("portal", "url")
print "use SateConfigParser() write"
cf.set("portal", "url2", "%(host)s:%(port)s")
print cf.get("portal", "url2")
得到终端输出(效果同ConfigParser):
use SafeConfigParser() read
http://localhost:8080/Portal
use SateConfigParser() write
localhost:8080
git的使用记录
1 | git clone https://code.jd.com/jd_49526c7409da9/jae_liuhongbin_2.git |
1 | git status |
1 | git add . |
1 | git commit -m 'new' |
1 | git push |
1 | git rm index.txt |
1 | git commit -m 'remove' |
1 | git push |
1 | git init |
研二这一年那点项目
前言
研二这一年一直待在南通,跟老板的项目(VB做的,对老板无语了,这么旧的东西还在坚持,还有其他各种无语,关于人品的——你懂得,就不在这里吐槽了)
下面直接记录这一年多对这个项目技术的一些总结。
直接采用VB6.0的 文件->生成
用setup factory 6.0进行打包
本文主要用于分享Spark的一些感悟
Mahout开发环境搭建及推荐系统初探
下载Maven:http://maven.apache.org/download.cgi
下载最新的xxx-bin.zip文件,在win上解压到 F:\ProgramFiles\maven-3.2.1
并把maven/bin目录设置在环境变量PATH:
然后,打开命令行输入mvn -version,我们会看到mvn命令的运行效果1
2
3
4
5
6
7Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T01:37:5
2+08:00)
Maven home: F:\ProgramFiles\maven-3.2.1\bin\..
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: F:\Program Files\Java\jdk1.6.0_20\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
安装Eclipse的Maven插件: http://www.eclipse.org/m2e/
1 | D:\Code\workspace>mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes |
进入项目,执行mvn命令
1 | D:\Code\workspace>cd myHadoop |
我们创建好了一个基本的maven项目,然后导入到eclipse中。 这里我们最好已安装好了Maven的插件。
这里我使用hadoop-1.0.3版本,修改文件:pom.xml1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43vi 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.conan.mymahout</groupId>
<artifactId>myMahout</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myMahout</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mahout.version>0.8</mahout.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>${mahout.version}</version>
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-integration</artifactId>
<version>${mahout.version}</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
</exclusion>
<exclusion>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
1 | mvn clean install |
在eclipse中刷新项目:
core-site.xml
hdfs-site.xml
mapred-site.xml1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19vim core-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://Master.Hadoop:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/hadoop/tmp</value>
</property>
<property>
<name>io.sort.mb</name>
<value>1024</value>
</property>
</configuration>
1 | vim hdfs-site.xml |
1 | vim mapred-site.xml |
1 | vi c:/Windows/System32/drivers/etc/hosts |
1 | mkdir datafile |
数据解释:每一行有三列,第一列是用户ID,第二列是物品ID,第三列是用户对物品的打分。
1 | package org.lhb.mymahout; |
1 | SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". |
向用户ID1,推荐前二个最相关的物品, 104和106
向用户ID2,推荐前二个最相关的物品, 但只有一个105
向用户ID3,推荐前二个最相关的物品, 103和102
向用户ID4,推荐前二个最相关的物品, 但只有一个102
向用户ID5,推荐前二个最相关的物品, 没有符合的
Hive学习笔记系列,Hive UDF函数开发
然后新建class package(com.jd.lhb) name(UDFLower)
添加hadoop-core-1.0.3.jar hive-exec-0.8.1.jar两个文件到project
build path
1 | package com.jd.lhb; |
1 | hive> add jar /home/hadoop/udf/HiveUDF.jar |
1 | WHO |
hive> create table dual (info string);
1 | hive> load data local inpath '/home/hadoop/data.txt' into table dual; |
1 | hive> create temporary function my_lower as 'com.afan.UDFLower'; |
1 | hive> select info from dual; |
Hive学习笔记系列,HQL:查询。
1 | select symbol,`price.*` from stocks; |
1 | A+B |
1 | round(Double d) 返回d的BIGINT类型的近似值 |
1 | sum(DISTINCT col) 指定列排重后的总和 |
注:可以通过设置属性hive.map.aggr的值为true来提高聚合的性能1
hive> set hive.map.aggr=true;
1 | explode(ARRAY array) 返回0到多行结果,每行都对应输入的array数组中的一个元素 |
1 | cast(<expr> as <type>) 将expr转化为type类型。 |